ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
My goal is to have a script where I can choose 3 different values for a var.
the var is a number , a datarate for making mp3
I have tried case
this works out
!!BUT
after the script 'finishes"
meaning
I can select a choice
that choice is a worthy var and I have made my mp3
the script does not - exit it returns to a prompt of
#?
and if I hit enter
i get the case menu selection again , and again until i do a cntrl c
here are my 2 efforts
vers1 just a case selection
vers2 a case selection nested in a do while ...that i hoped would fix it
----------:: v1 start
: 1
#!/bin/bash
## audio_defineDR_mp3.sh
PS4="Please select a data rate for your file "
select option in 128 192 256 quit
do
case $option in
128)
dr=128k
echo "128";;
192)
dr=192k
echo "192";;
256)
dr=256k
echo "256";;
quit)
break;;
esac
#done
ffmpeg -i /media/j/data/z/1.wav -codec:a libmp3lame -b:a $dr /media/j/data/z/1.mp3
echo finshed we hope ok
done
==================
v2--start
#!/bin/bash
## audio_defineDR_mp3.sh
select=0
while [ $select -eq 0 ]; do
#echo The count is $select
PS4="Please select a data rate for your file "
select option in 128 192 256 quit
do
case $option in
128)
dr=128k
let select=select+1
echo "128";;
192)
dr=192k
let select=select+1
echo "192";;
256)
dr=256k
let select=select+1
echo "256";;
quit)
break;;
esac
#done
echo $select
ffmpeg -i /media/j/data/z/1.wav -codec:a libmp3lame -b:a $dr /media/j/data/z/1.mp3
echo finshed we hope ok
done
done
exit is a bit drastic. break is enough to end the loop.
Indeed it makes you v1 script work as intended (I think).
A select loop is only ended with break.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.