posted: Jun 27 2009

bash loops part 2

so in a previous post i put up a how to do on renaming files in a for loop and string replacing. here is another example for taking files and renaming them all with lovely counts as well.

here is the line of code. that we will execute.

james@lappy2000:~/ count=1; for i in *.mp3; do mv "$i" "myband_${count}.mp3"; : $((count=count+1)); done

lets break it down for more details.
first off here is the count, we shall start with 1, you can start with any number you wish.

count=1;

your for loop, niotice we are putting the count in ${count}, now you can do this, or $count. either way is correct.

do mv  for i in *.mp3; do mv "$i" "myband_${count}.mp3";

you now see this. the colon basically says im a new command in this “do” section. and the double parens basically mean treat the insides like a variable.

: $((count=count+1));

thats basically it.

Your Ad Here



Leave a Comment

Please note: Comment moderation is enabled and may delay your comment. There is no need to resubmit your comment.

Get Adobe Flash playerPlugin by wpburn.com wordpress themes