You are not logged in.

#1 2004-10-08 16:29:52

flex_strongo
Member
Registered: 2003-12-02
Posts: 55

Bash Champions of the world, please help me!

Hey guys, I've been trying to write a bash script to handle my cdrecording.  What I'm trying to do is to get this script to convert mp3's and ogg's to wav format and burn them to an audio cd.  However my script seems to keep failing.  So I was hoping a bash scripting champion could help me out. Thanks

            #!/bin/bash
echo "Hey Brad, thanks for writing me! Choose an option: 1=Mp3audio 2=Oggaudio 3=Both 4=None, I'm stupid and invoked the wrong script"
echo "Choose your fate: 1, 2, 3, 4"
read opt
    
    if [ "$opt"="1" ]; then
      for a in *.mp3 ; do lame --decode "$a" ${a%.*}.wav
      echo Mp3's decoded
    elif [ "$opt"="2"]; then
      oggdec *.ogg
      echo Ogg's decoded
    elif [ "$opt"="3" ]; then
      for a in *.mp3 ; do lame --decode "$a" ${a%.*}.wav
      oggdec *.ogg
      echo Mp3's and Ogg decoded
    elif [ "$opt"="4" ]; then
      echo Well, at least you're honest.
      clear
      exit
    else
      clear
      echo That wasn't one of the options, you jerkface. No soup for you!
        fi
      normalize *.wav
      cdrecord dev=ATAPI:0,0,0 gracetime=2 driveropts=burnfree -audio -v -eject *.wav
done

Offline

#2 2004-10-08 16:33:29

phrakture
Arch Overlord
From: behind you
Registered: 2003-10-29
Posts: 7,879
Website

Re: Bash Champions of the world, please help me!

well, why not post what is failing.... the script output....

Offline

#3 2004-10-08 16:42:30

flex_strongo
Member
Registered: 2003-12-02
Posts: 55

Re: Bash Champions of the world, please help me!

I knew I forgot something: 

 ./cdscript: line 26: unexpected EOF while looking for matching '``
./cdscript: line 38: syntax error: unexpected end of file.

Thanks

Offline

#4 2004-10-08 16:54:51

kpiche
Forum Fellow
From: Ottawa, ON, Canada
Registered: 2004-03-30
Posts: 246
Website

Re: Bash Champions of the world, please help me!

It's the apostrophes in your echo statements.  Strings are delimited by " or ' so the shell is looking for the end of the string that starts with 's decoded.  Write:

echo "Mp3's decoded"

Offline

#5 2004-10-08 17:01:53

flex_strongo
Member
Registered: 2003-12-02
Posts: 55

Re: Bash Champions of the world, please help me!

That made perfect sense.  Thanks.  I got a new problem though....check this out:

 ./cdscript: line 11: syntax error near unexpected token 'elif'
           ./cdscript: line 11: '   elif [ "$opt" = "2" ]; then'

by the way I fixed all the quotations, I think...well here's the new code with the problem:

!/bin/bash -x
echo "Hey Brad, thanks for writing me! Choose an option: 1=Mp3audio
2=Oggaudio 3=Both 4=None, I'm stupid and invoked the wrong scrip"
echo "Choose your fate: 1, 2, 3, 4"
read opt

if [ "$opt" = "1" ]; then
          for a in *.mp3 ; do lame --decode "$a" ${a%.*}.wav
          echo "Mp3's decoded."

  elif [ "$opt" = "2" ]; then
          oggdec *.ogg;
          echo "Ogg's decoded."

  elif [ "$opt" = "3" ]; then
          for a in *.mp3 ; do lame --decode "$a" ${a%.*}.wav
          oggdec *.ogg
          echo "Mp3's and Ogg decoded"
elif [ "$opt" = "4" ]; then
            echo "Well, at least you're honest."
            clear
            exit
      else
            clear
            echo "That wasn't one of the options, you jerkface. No soup
for you!"

           fi

 normalize *.wav
          cdrecord dev=ATAPI:0,0,0 gracetime=2 driveropts=burnfree
-audio -v -eject *.wav
done

Offline

#6 2004-10-08 17:19:22

phrakture
Arch Overlord
From: behind you
Registered: 2003-10-29
Posts: 7,879
Website

Re: Bash Champions of the world, please help me!

i didn't think "elif" was valid - i thought it was "else if"...
dunno maybe i'm miking syntax...

Offline

#7 2004-10-08 17:20:21

dtw
Forum Fellow
From: UK
Registered: 2004-08-03
Posts: 4,439
Website

Re: Bash Champions of the world, please help me!

could you not use a case statement instead of the ifs?  have a read about that... i think you'll find it is much easier!

Offline

#8 2004-10-08 17:22:54

flex_strongo
Member
Registered: 2003-12-02
Posts: 55

Re: Bash Champions of the world, please help me!

I saw something about case statements.  I'll check it out. Thanks.  As far as I know elif is a valid bash statement.  But I could be wrong, I'm clearly no bash champion.

Offline

#9 2004-10-08 17:35:17

dp
Member
From: Zürich, Switzerland
Registered: 2003-05-27
Posts: 3,378
Website

Re: Bash Champions of the world, please help me!

have a look at this:

  AUSWAHL="not_at_all menuconfig xconfig oldconfig config"
           select opt in $AUSWAHL; do
               if [ "$opt" = "not_at_all" ]; then
                yes "" | make config || return 1
                mv $startdir/config.orig $startdir/config
                break
               elif [ "$opt" = "menuconfig" ]; then
                make menuconfig || return 1
                cp .config $startdir/config && echo "==> your config was saved to $startdir/config"
                break
               elif [ "$opt" = "xconfig" ]; then
                make xconfig || return 1
                cp .config $startdir/config && echo "==> your config was saved to $startdir/config"
                break
               elif [ "$opt" = "config" ]; then
                make config || return 1
                cp .config $startdir/config && echo "==> your config was saved to $startdir/config"
                break
               elif [ "$opt" = "oldconfig" ]; then
                make oldconfig || return 1
                cp .config $startdir/config && echo "==> your config was saved to $startdir/config"
                break
               else
                clear
                echo "==> I don't understand (bad option) ... assuming you don't want "
                echo "==> to configure and use the defaults."
                sleep 1
                echo "==> 3..."
                sleep 1
                echo "==> 2..."
                sleep 1
                echo "==> 1..."
                sleep 1
                echo "==> 0: GO! --------------------------- :-)"
                yes "" | make config || return 1
                mv $startdir/config.orig $startdir/config
                break
               fi
           done

it is taken from the PKGBUILD for kernel26mm:

http://cvs.archlinux.org/cgi-bin/viewcv … cvs-markup


The impossible missions are the only ones which succeed.

Offline

#10 2004-10-08 17:43:28

flex_strongo
Member
Registered: 2003-12-02
Posts: 55

Re: Bash Champions of the world, please help me!

Thanks for all the help guys....I've opted to go for the case statement. It does seem way easier.  Except I'm now getting this error:



./casscript: line 10: syntax error near unexpected token `;;'
./casscript: line 10: `          ;;'

here is the new case script:

#!/bin/bash -x
echo "Hey Brad, thanks for writing me! Choose an option: 1=Mp3audio 2=Oggaudio 3=Both 4=None, I'm stupid and invoked the wrong script"
echo "Choose your fate: 1, 2, 3, 4"
read opt

case $opt in
    1) for a in *.mp3 ; do lame --decode "$a" ${a%.*}.wav
      echo "Mp3's decoded"
        ;;
    2)oggdec *.ogg
      echo "Ogg's decoded"
        ;;
    3)for a in *.mp3 ; do lame --decode "$a" ${a%.*}.wav
      oggdec *.ogg
      echo "Mp3's and Ogg decoded"
        ;;
    4)echo "Well, at least you're honest."
      clear
      exit
        ;;
    *)clear
      echo "That wasn't one of the options, you jerkface. No soup for you!"
esac

normalize *.wav
      cdrecord dev=ATAPI:0,0,0 gracetime=2 driveropts=burnfree -audio -v -eject *.wav
done

Offline

#11 2004-10-08 18:06:34

phrakture
Arch Overlord
From: behind you
Registered: 2003-10-29
Posts: 7,879
Website

Re: Bash Champions of the world, please help me!

you "done" way at the bottom needs to be moved to the end of the "1)" case entry... done ends the for loop

Offline

#12 2004-10-08 18:13:12

flex_strongo
Member
Registered: 2003-12-02
Posts: 55

Re: Bash Champions of the world, please help me!

I changed that as you suggested, but error is still there.

Offline

#13 2004-10-08 18:24:01

phrakture
Arch Overlord
From: behind you
Registered: 2003-10-29
Posts: 7,879
Website

Re: Bash Champions of the world, please help me!

#!/bin/bash -x
echo "Hey Brad, thanks for writing me! Choose an option: 1=Mp3audio 2=Oggaudio 3=Both 4=None, I'm stupid and invoked the wrong script"
echo "Choose your fate: 1, 2, 3, 4"
read opt

case $opt in
   1) for a in *.mp3 ; do
     lame --decode "$a" ${a%.*}.wav
     echo "Mp3's decoded"
     done 
      ;;
   2)oggdec *.ogg
     echo "Ogg's decoded"
      ;;
   3)for a in *.mp3 ; do
     lame --decode "$a" ${a%.*}.wav
     oggdec *.ogg
     echo "Mp3's and Ogg decoded"
      ;;
   4)clear
     echo "Well, at least you're honest."
     exit
      ;;
   *)clear
     echo "That wasn't one of the options, you jerkface. No soup for you!"
esac

     normalize *.wav
     cdrecord dev=ATAPI:0,0,0 gracetime=2 driveropts=burnfree -audio -v -eject *.wav

Offline

#14 2004-10-08 18:28:08

flex_strongo
Member
Registered: 2003-12-02
Posts: 55

Re: Bash Champions of the world, please help me!

Hey! That worked great. Thanks!  I guess I got confused as to where to put the done.  Thanks again!

Offline

#15 2004-10-08 18:50:20

phrakture
Arch Overlord
From: behind you
Registered: 2003-10-29
Posts: 7,879
Website

Re: Bash Champions of the world, please help me!

FYI the "for" loop goes from the word "do" to "done", so it will execute all commands in there for each loop....
if the ";;" is in there, the for loop doesn't understand what to do with it, because ";;" is specific to a case statement and nothing else

Offline

#16 2004-10-08 19:09:14

cactus
Taco Eater
From: t͈̫̹ͨa͖͕͎̱͈ͨ͆ć̥̖̝o̫̫̼s͈̭̱̞͍̃!̰
Registered: 2004-05-25
Posts: 4,622
Website

Re: Bash Champions of the world, please help me!

yeah..don't forget the done in 3)


"Be conservative in what you send; be liberal in what you accept." -- Postel's Law
"tacos" -- Cactus' Law
"t̥͍͎̪̪͗a̴̻̩͈͚ͨc̠o̩̙͈ͫͅs͙͎̙͊ ͔͇̫̜t͎̳̀a̜̞̗ͩc̗͍͚o̲̯̿s̖̣̤̙͌ ̖̜̈ț̰̫͓ạ̪͖̳c̲͎͕̰̯̃̈o͉ͅs̪ͪ ̜̻̖̜͕" -- -̖͚̫̙̓-̺̠͇ͤ̃ ̜̪̜ͯZ͔̗̭̞ͪA̝͈̙͖̩L͉̠̺͓G̙̞̦͖O̳̗͍

Offline

Board footer

Powered by FluxBB