Handling Files with Whitespace in Bash
From Zanecorpwiki
Space in filenames is all fine and good, but it confuses older tools like bash. Bash uses whitespace as the delimiter for many operations, so when the files contain spaces, this causes bash to think the parts of the file are separate arguments to the command. (Even if bash were rebuilt today, this problem would probably persist as bash scripting is nothing more than a string of commands exactly as the user would type them and the space is the natural delimiter in this situation.)
In some cases, you can use quotes:
ls | awk '{print \$0\}'
This does not work with the for loop. In this case, one must run the names through 'read'
find . -name *.jpg | while read i; do echo $i done
So, to (recursively) change whitespace to underscore, you may do something like this:
find . -name *.jpg | while read i; do
j=`echo $i | tr [:space:] _`
mv $i ${j:0:$((${#j} - 1))} #removes trailing space generated by read
done


