[nylug-talk] renaming batches of files

Martin A. Brown martin-nylug at wonderfrog.net
Thu May 8 10:49:00 EDT 2003


Kevin,

Clever!

 : This is a riff on my fav little code snippett: note: I start at
 : 1000 so that the zeros are padding the space to the left of the
 : number. IE: 1 -> 1001, 2->1002. because d1..d9,d10 dont sort
 : well. whereas d1001...d1010 are ok. (bash only)
 :
 : I=1000; EXT="jpg"; ls *.$EXT| while read line; do
 : 	mv $line "d$I.$EXT";
           ^^^^^
           |||||
You, sensibly, go to lengths to put strings into $line with
whitespace, but you lose that whitespace in the mv command here, and
end up supplying (potentially) more than two arguments to mv if any
initial file contains a space in the name.

Try instead....

  mv "$line" "d${I}.$EXT"

 : 	I=$(($I+1));
 : done

Ciao for now,

-Martin



More information about the nylug-talk mailing list