[mdlug-newbie] question about scripting

Robert Citek robert.citek at gmail.com
Mon Jan 16 02:31:32 EST 2012


On Thu, Jan 5, 2012 at 4:23 PM, Mathew   May <mathewmay1 at wowway.com> wrote:
> Here is what I have so far:
>
> #!/bin/bash
> #ls -R | while read -r FILE
> for FILE in `find /home/mmay3/Music/tori_amos *.mp3 -type f`
> do
>   mv -v $FILE `echo $FILE | tr ' ' '_' | tr '[A-Z]' '[a-z]'`
> done

You are on the right track.  Combine the two and you would likely have
eventually got it:

#!/bin/bash
find /home/mmay3/Music/tori_amos -iname '*.mp3' -type f |
while read FILE
do
  mv -v "$FILE" `echo $FILE | tr ' ' '_' | tr '[A-Z]' '[a-z]'`
done

Changes:

1) used a while loop instead of a for loop
2) corrected the syntax of the find
3) placed quotes around $FILE

I would have made two more changes to yield this mv command:

  mv "$FILE" "$(echo $FILE | tr ' A-Z' '_a-z')"

1) uses $() instead of backticks ``
2) collapses the two tr commands into one

Your logic was sound, just your syntax needed a little tweaking.

Regards,
- Robert



More information about the mdlug-newbie mailing list