how to break within a case/esac and stay in script


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers how to break within a case/esac and stay in script
# 1  
Old 03-22-2005
how to break within a case/esac and stay in script

Wrote the following loop to but if I use exit, then I break entirely from my script, but instead I want to break from the case/esac and go to the next line in my script. I guess I need to know how to exit gracefully from a "while (true). Also, how can I allow the user to enter upper or lowercase as valid responses. An "A", will be treated the same as an "a", without replicating logic?

Code:
while (true)
do
  echo "  a b c "   
  echo " Enter one of the environments from above: \c"
  read reply
   case $reply in
      a)  echo a is valid & exit  ;;        
      b)  echo b is valid & exit ;;
      c)  echo c is valid & exit ;;
      *)  echo $reply is not valid - try again
   esac
done

# 2  
Old 03-22-2005
Change your "exit" statements within each case to break. For the upper case/lower case, its easier to allow the user to enter either but allow your script to evaluate only 1. You can do this by typing your variable reply as either uppercase or lowercase using the typeset command. Outside of the while loop, you may break out of the loop by either changing the condition that you are using to loop or by using another break command.

Example.

typeset -u reply (this will cause the input to be shifted to upper case. So when the user enters 'a', the script reads 'A'). typeset -l is the complement to the -u flag. It changes things to lower case.

Be sure to change your case statement accordingly to match for either upper or lower case.
# 3  
Old 01-23-2009
I have a query on this break. I am using a program where I am using a while loop to execute it. It will get into a file take the first file and then ping it and if the ip is reachable then it will mail. Now what happens is that when i ping the ip it does nopt come out of the loop and it says "reply from reply from" . I need to usse a break statemetn to come out of this. Can you assist me in this.
# 4  
Old 01-24-2009
break out of ping

Sounds like you just have to change your ping command. Try using 'ping -c 1 <some_host>'. That will try to ping only once instead of constantly.

HTH
# 5  
Old 04-12-2009
What about when exiting from a loop and a case? such like...

Code:
case $CASE in
1)

2)
   while ps $PID
   do
      if [ $? -eq 0 ];then
         echo "exit from this while loop and exit from case, how will I do that?"
      fi
   do

3)

...

esac

 
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Case -- esac number of arguments problem

hi Scripting experts, I am using case..esac in my script .. I have given 6 option..e.g. 1 2 3 4 5 and *, howerver my script works welll for 1st 4 options but for 5 it considers * and exists. Is there a maximum limit on number of options given for case ..esac? (1 Reply)
Discussion started by: sdgawande
1 Replies

2. Programming

Need a tracking PHP Script – “how long people stay on the website?”

I want to know, is there a way to track how long anyone has been logged into website and then insert it up for each time they have logged on. In case, user a logs in for 30 minutes, then later comes back and logs in for an hour, then later comes back and logs in for 50 minutes, Add... (1 Reply)
Discussion started by: AimyThomas
1 Replies

3. UNIX Desktop Questions & Answers

Specifying a range within case/esac

Complete Unix beginner here. I basically have this script - This seems to work fine. I want to try and shorten it by making it something like this - This isn't working. I think it's probably to do with the zero padding that `date +%H` gives me, but if I use `date +%k`, I get a space at... (3 Replies)
Discussion started by: Orbient
3 Replies

4. Shell Programming and Scripting

something is causing this script to break early on

I am relatively new at scripting in linux. Most of my scripting knowledge comes from doing batch scripting in windows. Anyway, I have this script I'm trying to write that will install a program called Nagios along with a few other packages. I know it has to be something at the beginning that is... (4 Replies)
Discussion started by: nanite51
4 Replies

5. UNIX for Dummies Questions & Answers

script dont' break out

I have concurrent manager stop and check to verify all the process are stopped BUT even after all the process are stopped query script continues to run without break out. # stop the concurrent manager $COMMON_TOP/admin/scripts/$CONTEXT_NAME/adstpall.sh $DB_USER/$DB_PSWD # check if the... (1 Reply)
Discussion started by: Paul.S
1 Replies

6. Shell Programming and Scripting

Script to Convert Upper case to Lower case

Hi All I have a script which extracts values from a Database (A persons name) and puts it into a variable in my script IE: $NAME However the Value in the DB is all in uppercase and contains the users first name and last name EG: > echo $NAME GRAHAM BOYLE > What I need is only the... (7 Replies)
Discussion started by: grahambo2005
7 Replies

7. Shell Programming and Scripting

Script needed to select and delete lower case and mixed case records

HELLO ALL, URGENTLY NEEDED A SCRIPT TO SELECT AND DELETE LOWER AND MIXED CASE RECORDS FROM A COLUMN IN A TABLE. FOR EXAMPLE : Table name is EMPLOYEE and the column name is CITY and the CITY column records will be: Newyork washington ... (1 Reply)
Discussion started by: abhilash mn
1 Replies

8. UNIX for Dummies Questions & Answers

lower case to upper case string conversion in shell script

How can convert a Lower case variable value to an upper case in the kron shell script. (3 Replies)
Discussion started by: dchalavadi
3 Replies
Login or Register to Ask a Question