This typically happens if the files (ie pictures) originated from a Windows host. I’ve found it’s much easier to just remove the spaces in the files than to deal with trying to properly quote your escapes in your loops. Â
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
for oldname in * do newname=`echo $oldname | sed -e 's/ /_/g'` if [ "$newname" = "$oldname" ] then continue fi if [ -e "$newname" ] then echo Skipping "$oldname", because "$newname" exists else mv "$oldname" "$newname" fi done |