You are not logged in.
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
well, why not post what is failing.... the script output....
Offline
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
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
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
i didn't think "elif" was valid - i thought it was "else if"...
dunno maybe i'm miking syntax...
Offline
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
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
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:
The impossible missions are the only ones which succeed.
Offline
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
you "done" way at the bottom needs to be moved to the end of the "1)" case entry... done ends the for loop
Offline
I changed that as you suggested, but error is still there.
Offline
#!/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
Hey! That worked great. Thanks! I guess I got confused as to where to put the done. Thanks again!
Offline
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
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