re bash script help

re bash script help

Post by faeychil » Sun, 13 Apr 2003 14:28:26



Have tried both suggested scripts to convert
wave files to mp3 .
**********************
 #!/bin/bash
  for i in *.mp3; do
    mpg321 --w - "$i"  > `basename $i .mp3`.wav
  done

script error "basename:  too many arguments"

It would seem to be caused by long filenames with spaces
enclosing the name in quotes is a cure but that would require
a loop script too.

********************
for I in *.mp3
do
        mpg321 --w - $I  >  ${I%.mp3}.wav
done

script error "ambiguous redirect"
file lengh has no effect on this one

******************
any suggested mods

--
faeychild

 
 
 

re bash script help

Post by Dr. Yuan Li » Sun, 13 Apr 2003 15:24:39



> Have tried both suggested scripts to convert
> wave files to mp3 .
> **********************
>  #!/bin/bash
>   for i in *.mp3; do
>     mpg321 --w - "$i"  > `basename $i .mp3`.wav
>   done

> script error "basename:  too many arguments"

> It would seem to be caused by long filenames with spaces
> enclosing the name in quotes is a cure but that would require
> a loop script too.

(comp.unix.shell would be more appropriate.) I don't quite see what's
wrong with `basename "$i" .mp3`.wav; what do you mean by require a loop
script?  You are already using a loop, do you mean to eliminate for
construct?

Yuan Liu

Quote:> ********************
> for I in *.mp3
> do
>         mpg321 --w - $I  >  ${I%.mp3}.wav
> done

> script error "ambiguous redirect"
> file lengh has no effect on this one

> ******************
> any suggested mods


 
 
 

re bash script help

Post by dav.. » Sun, 13 Apr 2003 15:29:58


Quote:> It would seem to be caused by long filenames with spaces

If you have spaces in the filenames then the "for" loop will not
work, since he uses the space to "break" the elements. You have
to change the "break" char too.

I'd go for a quick-dirty solutions:

mpg321 --w - $i > $i.wav

This will create a file called *.mp3.wav that you can rename
later (or just keep it like this).

Davide

 
 
 

re bash script help

Post by faeychil » Sun, 13 Apr 2003 17:07:17



>> It would seem to be caused by long filenames with spaces

> If you have spaces in the filenames then the "for" loop will not
> work, since he uses the space to "break" the elements. You have
> to change the "break" char too.

> I'd go for a quick-dirty solutions:

> mpg321 --w - $i > $i.wav

> This will create a file called *.mp3.wav that you can rename
> later (or just keep it like this).

> Davide

I have 300+ mp3 files to convert !!!!!!!

I must loop :-)

--
faeychild

 
 
 

re bash script help

Post by Jonathan A » Sun, 13 Apr 2003 18:24:13


On Sat, 12 Apr 2003 08:07:17 GMT, faeychild


>>> It would seem to be caused by long filenames with spaces

>> If you have spaces in the filenames then the "for" loop will not
>> work, since he uses the space to "break" the elements. You have
>> to change the "break" char too.

>> I'd go for a quick-dirty solutions:

>> mpg321 --w - $i > $i.wav

>> This will create a file called *.mp3.wav that you can rename
>> later (or just keep it like this).

>> Davide

> I have 300+ mp3 files to convert !!!!!!!

> I must loop :-)

This seems to work here... spaces and all:

for f in *.mp3; do
 mpg321 -vv -w "`echo $f | sed -e "s/\.mp3//g"`.wav" "$f"
done

HTH,
Jonathan

--
Don't just hit reply. Email address is broken. Thank
your friendly neighborhood spammer. Email replies to:
user: jnthn1                domain: earthlink<dot>net

 
 
 

re bash script help

Post by Peter T. Breue » Sun, 13 Apr 2003 18:23:49



>> It would seem to be caused by long filenames with spaces
> If you have spaces in the filenames then the "for" loop will not
> work, since he uses the space to "break" the elements. You have
> to change the "break" char too.

That is not true. It works fine. Please do not use quotes when you
"say" things - it gives us the impression you do not know what the
words mean.

Peter

 
 
 

re bash script help

Post by Peter T. Breue » Sun, 13 Apr 2003 18:22:17



> Have tried both suggested scripts to convert
> wave files to mp3 .
> **********************
>  #!/bin/bash
>   for i in *.mp3; do
>     mpg321 --w - "$i"  > `basename $i .mp3`.wav
>   done
> script error "basename:  too many arguments"
> It would seem to be caused by long filenames with spaces

spaces! Don't do that. But

     `basename "$i" .mp3`.wav  

would "fix" it. You didn't say anything about spaces.

Quote:> enclosing the name in quotes is a cure but that would require
> a loop script too.

Eh? What do you mean?

Quote:> ********************
> for I in *.mp3
> do
>         mpg321 --w - $I  >  ${I%.mp3}.wav
> done
> script error "ambiguous redirect"
> file lengh has no effect on this one

Same "problem".

Quote:> ******************
> any suggested mods

Only the obvious one. That's trivia. Next time don't have names with
spaces in. or SAY if you do - you can't expect a solution to a problem
unless you state what the problem is.

Peter

 
 
 

re bash script help

Post by Michael Heimin » Sun, 13 Apr 2003 18:38:26




>> Have tried both suggested scripts to convert
>> wave files to mp3 .
>> **********************
>>  #!/bin/bash
>>   for i in *.mp3; do
>>     mpg321 --w - "$i"  > `basename $i .mp3`.wav
>>   done
>> script error "basename:  too many arguments"
>> It would seem to be caused by long filenames with spaces
> spaces! Don't do that. But

It's a cancer those space in file/directory names, somehow reminds
me of M$. It's a good idea to avoid them like hell or one might run
from one trouble to another. Sadly it's pretty common with .mp3 file
names.;(

--
Michael Heiming

Remove +SIGNS and www. if you expect an answer, sorry for
inconvenience, but I get tons of SPAM

 
 
 

re bash script help

Post by Peter T. Breue » Sun, 13 Apr 2003 18:53:29



> On Sat, 12 Apr 2003 08:07:17 GMT, faeychild


[ much NONSENSE snipped]

Quote:>> I must loop :-)
> This seems to work here... spaces and all:

Puhleeeese! There was nothing he needed to to except put quotes around
the "$i" or "$I" or wnatever it was.

Peter

 
 
 

re bash script help

Post by Dave Brow » Mon, 14 Apr 2003 00:51:55



>...
>>> It would seem to be caused by long filenames with spaces
>...
> It's a cancer those space in file/directory names, somehow reminds
> me of M$. It's a good idea to avoid them like hell or one might run
> from one trouble to another. Sadly it's pretty common with .mp3 file
> names.;(

In the loop, you can modify the filename being worked:

  name=${name// /_}

which will replace the spaces with "_".  Then the resulting output
file will also be devoid of spaces.  Most mp3 players I've seen will
not display a "_" in the name, so your names look just fine.

(See bash manpage "Parameter Expansion".)

--
Dave Brown  Austin, TX

 
 
 

re bash script help

Post by William Par » Mon, 14 Apr 2003 02:18:44



> Have tried both suggested scripts to convert
> wave files to mp3 .
> **********************
> #!/bin/bash
>  for i in *.mp3; do
>    mpg321 --w - "$i"  > `basename $i .mp3`.wav
>  done

> script error "basename:  too many arguments"

This cannot happen.  If there were spaces, then your for-loop would have
broken it up, so that each $i will be without spaces.  Try
    for i in *.mp3; do
        echo $i
    done
and see what happens.

--

Linux solution for data management and processing.

 
 
 

re bash script help

Post by Peter T. Breue » Mon, 14 Apr 2003 03:02:11




>> Have tried both suggested scripts to convert
>> wave files to mp3 .
>> **********************
>> #!/bin/bash
>>  for i in *.mp3; do
>>    mpg321 --w - "$i"  > `basename $i .mp3`.wav
>>  done

>> script error "basename:  too many arguments"
> This cannot happen.  If there were spaces, then your for-loop would have
> broken it up, so that each $i will be without spaces.  Try

No! It can happen and the only thing that he needs is "$i" instead of $i.

The expansion of *.mp3 will result in several distinct strings, each
with spaces in, which $i takes the value of in turn.  The $i variable
needs protection after it's expanded by the shell, or the basename
subprocess will receive several arguments where it expects one.

Peter

 
 
 

re bash script help

Post by Dan Espe » Mon, 14 Apr 2003 03:14:19




>> Have tried both suggested scripts to convert
>> wave files to mp3 .
>> **********************
>> #!/bin/bash
>>  for i in *.mp3; do
>>    mpg321 --w - "$i"  > `basename $i .mp3`.wav
>>  done

>> script error "basename:  too many arguments"

> This cannot happen.  If there were spaces, then your for-loop would have
> broken it up, so that each $i will be without spaces.  Try
>     for i in *.mp3; do
>    echo $i
>     done
> and see what happens.

As another poster said, for won't break up the names:

home> mkdir junk
home> cd junk
home> >"space in name".mp3
home> >"nospaceinname".mp3
home> ll
total 0
-rw-rw-r--    1 dane     dane            0 Apr 12 14:12 nospaceinname.mp3
-rw-rw-r--    1 dane     dane            0 Apr 12 14:11 space in name.mp3
home> for i in *.mp3 ; do echo $i ; done
nospaceinname.mp3
space in name.mp3

 
 
 

re bash script help

Post by William Par » Mon, 14 Apr 2003 05:21:27



Quote:>>>  for i in *.mp3; do
>>>    mpg321 --w - "$i"  > `basename $i .mp3`.wav
>>>  done

>>> script error "basename:  too many arguments"

>> This cannot happen.  If there were spaces, then your for-loop would have
>> broken it up, so that each $i will be without spaces.  Try

> No! It can happen and the only thing that he needs is "$i" instead of $i.

> The expansion of *.mp3 will result in several distinct strings, each
> with spaces in, which $i takes the value of in turn.  The $i variable
> needs protection after it's expanded by the shell, or the basename
> subprocess will receive several arguments where it expects one.

I stand corrected.  

--

Linux solution for data management and processing.

 
 
 

re bash script help

Post by faeychil » Mon, 14 Apr 2003 16:00:52




>> Have tried both suggested scripts to convert
>> wave files to mp3 .
>> **********************
>>  #!/bin/bash
>>   for i in *.mp3; do
>>     mpg321 --w - "$i"  > `basename $i .mp3`.wav
>>   done

>> script error "basename:  too many arguments"

>> It would seem to be caused by long filenames with spaces

> spaces! Don't do that. But

>      `basename "$i" .mp3`.wav

> would "fix" it. You didn't say anything about spaces.

In the begining I was not aware that spaces would have any effect
 But after renaming a test mp3 file to a single name the program
ran and I realized it must be the spaces.
The other 300+ files are all long names with spaces and will crash the
loop

I tried the quotes around the variable after basename and the error is now

./conv1.sh: `basename "$i" .mp3`: ambiguous redirect

--
faeychild

 
 
 

1. bash script help

I have no bash script skills at all

I want to convert 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 "file.mp3.wav".
Obviously I want only ".wav".

The "correct" script would be appreciated.

#!/bin/bash

for I in *.mp3

do

        mpg321 --w - "$I"  > "$I".wav

done

--
faeychild

2. PnP modem problems

3. Folding @ Home - distributed computing for Linux

4. simple bash script help

5. Booting Linux

6. Linux BASH Script HELP!!!!!

7. crontab + logger

8. Passing option to bash script help needed

9. Simple bash script help?

10. re bash script help

11. Bash script help..

12. BASH script help