LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 08-13-2019, 01:54 PM   #1
zimbot
Member
 
Registered: Nov 2005
Location: cincinnati , ohio . USA
Distribution: ubuntu , Opensuse , CentOS
Posts: 179

Rep: Reputation: 17
my case loop never ends


Friends,

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

-v2 end

I am on ubuntu 18.04

thanks in advance!
 
Old 08-13-2019, 02:18 PM   #2
ondoho
LQ Addict
 
Registered: Dec 2013
Posts: 19,872
Blog Entries: 12

Rep: Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053
Because that's how select works.
See:
Code:
help select
If you want to quit after the ffmpeg command, simply add 'exit':
Code:
...
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
exit
...
 
Old 08-21-2019, 02:22 PM   #3
MadeInGermany
Senior Member
 
Registered: Dec 2011
Location: Simplicity
Posts: 2,789

Rep: Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201
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.
 
Old 08-21-2019, 02:27 PM   #4
MadeInGermany
Senior Member
 
Registered: Dec 2011
Location: Simplicity
Posts: 2,789

Rep: Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201
You can enhance your script with
Code:
*)
continue;;
Before the esac
 
Old 08-23-2019, 09:39 PM   #5
Skaperen
Senior Member
 
Registered: May 2009
Location: center of singularity
Distribution: Xubuntu, Ubuntu, Slackware, Amazon Linux, OpenBSD, LFS (on Sparc_32 and i386)
Posts: 2,684
Blog Entries: 31

Rep: Reputation: 176Reputation: 176
you can enhance your posting by putting [/code] after your code ends and putting [code] before your code begins.
Code:
like
this
    and
        you
            can
                indent,
                    too
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: For world’s biggest troll, first patent case ends up in tatters LXer Syndicated Linux News 0 04-23-2014 06:20 AM
LXer: SCO - The party never ends LXer Syndicated Linux News 0 09-21-2009 05:11 PM
LXer: Work Never Ends! More Unix/Linux Cartoons LXer Syndicated Linux News 0 03-15-2009 04:30 PM
It never ends.. Jeebizz General 9 02-22-2009 12:09 PM
Apollon... Conecting... Never ends.. doraimom Linux - Software 0 12-17-2008 08:46 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:17 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration