Re: Whitespace in filenames



soup_or_power@xxxxxxxxx wrote:

I have inherited some code that looks like this:
if [ ! -f $file ]
then
echo "Error Can't clean >$file<. May have spaces in the
name?"
else
mv "$file" DEL.$file
fi

I have these questions:

a) can it be rewritten as if [ ! -f "$file" ]...
b) change the mv as mv "$file" "DEL.$file"

Yes...until you hit a file with a double-quote in the file name :P But
that's a whole other world of pain. Your proposed solution will work on
files with spaces and most other non-printable/unicode/etc text elements.

Cheers,

James
--
You'll be sorry...

.



Relevant Pages