Duncan Anderson wrote:
Mikkel L. Ellertson wrote:

I like to make scripts a bit more "bullet proof"... I would probably change it to:

for i in *.mp3 ; do
   name=$(basename "$i" .mp3)
   mpg123 -s "$name.mp3" | sox -f 44100 -w -s -c 2 - "$name.wav"
done

This way, it handles files with spaces in the name, and you avoid having to use a temp file. The error generated by a file with a space in its name would not be a problem by itself, and using a temp file would not be a problem by it self. but if you get the wrong name, you could delete something other then what you intended to. For example, if you had a file called "bridge over troubled water.mp3" and you also had a file called "bridge" in the same directory, you script would first overwrite, then delete "bridge". Using "basename" in place of "FILE=`echo $FILE | sed s/.mp3//g`" also solves the problem of a file with ".mp3" in more then one place in the name. It would probably not be a problem in any case, but you never know.

Mikkel


You are a scriptmaster of note, Mikkel. My version of the script works for me, because I always make sure that there are no spaces in the names first. Your refinement allows one to be more lazy!

regards
Duncan

It comes from interacting with Windows users too much. After a while, you get in the habit of writing the scripts so the Windows file names don't break them. You also try to build them as safe as possible...

Some things I try to keep in mind when writing scripts:

lower case names for local varables - so you don't break things if you deside to source the code from another script.

<name>.$$ for temp file names, so if two coppies of the script use the same directory for temp files, they don't interfere with each other.

If you can use a pipe in place of a temp file, do so.

If one of several commands can be used in a script, set a varable with the command name at the start of the script, and use the varable name in the script itself. That way, if you move the script to another system, all you need to do is edit one line at the start of the script.

Mikkel
--

  Do not meddle in the affairs of dragons,
for you are crunchy and taste good with Ketchup!

____________________________________________________
Want to buy your Pack or Services from MandrakeSoft? 
Go to http://www.mandrakestore.com
Join the Club : http://www.mandrakeclub.com
____________________________________________________

Reply via email to