The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
google unix.com



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
case in script jazz8146 UNIX for Dummies Questions & Answers 8 04-28-2008 06:23 AM
How does the environment stay set gzs553 Shell Programming and Scripting 1 03-18-2008 12:21 PM
Script needed to select and delete lower case and mixed case records abhilash mn Shell Programming and Scripting 1 03-17-2008 08:00 AM
ksh script: 'exit' being treated as 'break 2' gsatch Shell Programming and Scripting 4 08-11-2003 12:59 PM
lower case to upper case string conversion in shell script dchalavadi UNIX for Dummies Questions & Answers 3 05-29-2002 01:07 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 03-22-2005
tumblez tumblez is offline
Registered User
  
 

Join Date: Nov 2002
Posts: 15
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?

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 (permalink)  
Old 03-22-2005
google's Avatar
google google is offline Forum Advisor  
Moderator
  
 

Join Date: Jul 2002
Location: Atlanta
Posts: 740
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 (permalink)  
Old 01-23-2009
venkidhadha venkidhadha is offline
Registered User
  
 

Join Date: Aug 2008
Posts: 19
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 (permalink)  
Old 01-24-2009
homeyjoe homeyjoe is offline
Registered User
  
 

Join Date: Jan 2009
Location: Minnesota
Posts: 63
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 (permalink)  
Old 04-12-2009
Orbix Orbix is offline
Registered User
  
 

Join Date: Nov 2007
Posts: 34
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
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 03:46 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0