Bash: working with filenames containing spaces

At times, I'd like to perform an action against all files in a directory like this:


for i in `find . -type f`
do
cp "${i}" "${i}.bak"
done


This fails when filenames contain spaces, as bash uses whitespace, tab and LF as the default delimiter. Solution? Do this:


SAVEIFS=$IFS
IFS=$(echo -en "\n\b")


#bash

People Who Wowed This Post

×
  • If you are a bloguru member, please login.
    Login
  • If you are not a bloguru member, you may request a free account here:
    Request Account