Nested case


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Nested case
# 1  
Old 12-02-2011
Nested case

Hi there,

I have nested case in my script. I am asking user, want to continue? if user press y/Y then my inner case should continue, rather than that my code start from beginning. I would like to continue my inner case until user press n or N. Is any one tell me how can I do?

Thanking You,
SmilieSmilie
# 2  
Old 12-03-2011
Can you please post the code you have?
# 3  
Old 12-05-2011
Hi Jim,

I am very sorry to delay reply. Please find my code as follow:

Code:
#!/usr/bin/sh
wantMore ()
{
echo "Do you want to do more? "
echo "Enter either "y or Y" to continue or "n or N" to exit."
read key
case "$key" in

[yY]) continue
;;
[nN]) exit ;;
esac 
}

while true
do
clear
echo "**************************************************** 
* Main Menu *
**************************************************** 
1. aaaaaaaaaa 
2. bbbbbbbbbbb
3. ccccccccccccc 
4. ddddddddd 
5. Quit. 
*****************************************************"
echo "Enter your choice: "
read choice

case "$choice" in 
1) some code
wantMore
;; 

2) some code 
wantMore
;;
3) 
clear
echo "**************************************************** 
* Modify Menu *
**************************************************** 
a. aaaaaaaaaaa.
b. bbbbbbbb
c. ccccccccc
d. dddddddddd
e. eeeeeeeeee
*****************************************************"
echo "Enter your selection: "
read option
case "$option" in
[aA]) some code
wantMore
;;
[bB]) some code
wantMore
;;
[cC]) some code
wantMore
;;
[dD]) some code
wantMore
;;
[eE]) some code
wantMore
;;
esac
;;
4) some code
wantMore ;; 
5) echo "Good Bye!!!" 
exit ;;

*) echo Please enter valid option.
sleep 2 
continue 1;;
esac
done

I would like to remian in appropriate case until user say n/N.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Nested case: rsync command not found

Hello! Below my first bash script. As you can see i build 2 nested cases. The second one (sync databases) is working fine. Bu the first one (sync datadirs) is not working. It says: rsync: command not found. However when i move the rsync command to the top of the script its working. So i suppose... (2 Replies)
Discussion started by: hyperconnected
2 Replies

2. Shell Programming and Scripting

Change first letter of a word from lower case to upper case

Hi all, I am trying to find a way to change first letter in a word from lower case to upper case. It should be done for each first word in text or in paragraph, and also for each word after punctuation like . ; : ! ?I found the following command sed -i 's/\s*./\U&\E/g' $@ filenamebut... (7 Replies)
Discussion started by: georgi58
7 Replies

3. Shell Programming and Scripting

Nested case inside awk

please let me know if the below code could be written efficiently inside single awk case "$INP" in ksh) cat catalog | awk 'BEGIN {FS=",";} { print $2 } END {}' ;; pset) cat catalog | awk 'BEGIN {FS=",";} { print $3 } END {}' ;; dml) cat catalog | awk 'BEGIN {FS=",";} {... (2 Replies)
Discussion started by: cvsanthosh
2 Replies

4. Shell Programming and Scripting

Conversion from Upper Case to Lower Case Condition based

Hello Unix Gurus : It would be really appreciative if can find a solution for this . I have records in a file . I need to Capitalize the records based on condition . For Example i tried the following Command COMMAND --> fgrep "2000YUYU" /export/home/oracle/TST/data.dat | tr '' ''... (12 Replies)
Discussion started by: tsbiju
12 Replies

5. Shell Programming and Scripting

If-statement nested in case

I'm trying to write case statements with 'if statements' embedded inside of them. I'm using the korn shell but it's not functioning. If I want to see if a string exists in a file and then perform an action, what would be the best way to do this? For file "asg51fin" to delete a line if a... (1 Reply)
Discussion started by: dazeman27
1 Replies

6. Shell Programming and Scripting

data array needs to change upper case to lower case

Hi all, i have a data array as followes. ARRAY=DFSG345GGG ARRAY=234FDFG090 ARRAY=VDFVGBGHH so on.......... i need all english letters to be change to lower case. So i am expecting to see ARRAY=dfsg345ggg ARRAY=234fdfg090 ARRAY=vdfvgbghh so on........ If i have to copy this data in... (8 Replies)
Discussion started by: usustarr
8 Replies

7. Shell Programming and Scripting

Nested Case in UNIX script

Hi I wanted to know if we can write a nested case in UNIX script. Something like following - Case ${sDB} in Srvr1) case ${sSchema} Sch1) DBusr=Username1 DBPwd=Pwd1 ;; Sch2) DBusr=Username2 ... (1 Reply)
Discussion started by: sumeet
1 Replies

8. 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

9. 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