[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Using stupid filenames in shell scripts



On Sat, May 17, 2003 at 07:54:25AM -0400, Kevin Mark wrote:
> I'm not sure what this is exactly but I have a rename script for this:
> rename *.ext to *.abc
> 
> ls *.ext | while read file; do

Not sure that's space-safe; 'for file in *.ext' would be safer and
simpler.

> 	OLD="$file"
> 	NAME=$(basename "$file" .ext)

You need double quotes around $(...). Alternatively, "${file%.ext}"
works.

> 	NEW="$NAME.abc"
> 	mv $OLD $NEW
> done

You need double quotes around both $OLD and $NEW.

Cheers,

-- 
Colin Watson                                  [cjwatson@flatline.org.uk]



Reply to: