simple bash script help

simple bash script help

Post by faeychil » Sun, 13 Apr 2003 17:30:11



Redhat 7.3

I have no bash script skills at all - need all the help I
can get.

I want to convert a collection of mp3 files to wave or cdr.

Using a script ripped off from the cdwrite howto ( below )
the result is a wave file with two extensions ; eg "file.mp3.wav".
Obviously I want only ".wav".

                        _____________

#!/bin/bash

for I in *.mp3
do
        mpg321 --w - "$I"  > "$I".wav
done
                       -----------------------

Two script modifcations I received produce errors

script 1

#!/bin/bash
for I in *.mp3
do
        mpg321 --w - $I  >  ${I%.mp3}.wav
done

this one reports  "ambiguous redirect"

                  --------------
script 2

 #!/bin/bash
  for i in *.mp3; do
    mpg321 --w - "$i"  > `basename $i .mp3`.wav
  done

this one reports "basename: too many arguments"
probably due to the spaces in the filenames

I would appreciate any suggestion to modify either

--
faeychild

 
 
 

simple bash script help

Post by Brendon Caligar » Sun, 13 Apr 2003 17:43:33



Quote:> Redhat 7.3

> I have no bash script skills at all - need all the help I
> can get.

> I want to convert a collection of mp3 files to wave or cdr.

> Using a script ripped off from the cdwrite howto ( below )
> the result is a wave file with two extensions ; eg "file.mp3.wav".
> Obviously I want only ".wav".

>                         _____________

Try this:

for fubar in *wav; do mv $fubar `basename $fubar .mp3.wav`.wav; done

B

 
 
 

simple bash script help

Post by Stephane CHAZELA » Sun, 13 Apr 2003 19:41:38


[...]

Quote:> #!/bin/bash
> for I in *.mp3
> do
>         mpg321 --w - $I  >  ${I%.mp3}.wav
> done

> this one reports  "ambiguous redirect"

for i in ./*.mp3; do
  mpg321 --w - "$i" > "${i%.mp3}.wav"
done

A non-quoted variable is a list in bash and Bourne compatible
shells. Here, your files probably have IFS chars (blanks) in
them.

With zsh:

for i (./*.mp3){mpg321 --w - $i > ${i:r}.wav}

--
Stphane

 
 
 

simple bash script help

Post by faeychil » Mon, 14 Apr 2003 15:30:31





>> Redhat 7.3

>> I have no bash script skills at all - need all the help I
>> can get.

>> I want to convert a collection of mp3 files to wave or cdr.

>> Using a script ripped off from the cdwrite howto ( below )
>> the result is a wave file with two extensions ; eg "file.mp3.wav".
>> Obviously I want only ".wav".

>>                         _____________
> Try this:

> for fubar in *wav; do mv $fubar `basename $fubar .mp3.wav`.wav; done

> B

Rename the end result files!!!! --  never thought of that  :-)
thanks
--
faeychild