Nested Case in UNIX script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Nested Case in UNIX script
# 1  
Old 05-03-2009
Nested Case in UNIX script

Hi

I wanted to know if we can write a nested case in UNIX script.

Something like following -

Code:
Case ${sDB} in
Srvr1)
        case ${sSchema}
        Sch1)
                DBusr=Username1
                DBPwd=Pwd1
        ;;
        Sch2)
                DBusr=Username2
                DBPwd=Pwd2
        ;;
             *) echo "Incorrect Schema name"
        ;;
        esac
;;
Srvr2)
        case ${sSchema}
        Sch3)
                DBusr=Username3
                DBPwd=Pwd3
        ;;
        Sch4)
                DBusr=Username4
                DBPwd=Pwd4
        ;;
             *) echo "Incorrect Schema name"
        ;;
        esac
;;
*) echo "Incorrrect Server Name"
;;
esac

Any suggestion is appreciated.

Thanks
Sumeet

Last edited by sumeet; 05-03-2009 at 09:17 PM..
# 2  
Old 05-04-2009

Yes you can, but in your example you are missing the in from the inner case statements.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Case statement in UNIX shell script

have written the below code to check whether the string received from user is a file name or dir using case statement, but its going into default case*). #!/bin/sh #Get a string from user and check whether its a existing filename or not rm str2 rm str3 echo "enter a file \c" read fil... (8 Replies)
Discussion started by: Mohan0509
8 Replies

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

3. Shell Programming and Scripting

Help on case to call recursively in UNIX Shell Script

Hi, I am New to Unix Shell Scripting basically, i need some help in achieving a case statement in Shell script to call recursively That is if case having like 1 2 3 4 options , if user inputs 1 and gets executed case should ask for options again but user should not input the same input value 1,... (7 Replies)
Discussion started by: karthikram
7 Replies

4. Shell Programming and Scripting

UNIX script -- case

i could like to try when i input a integer , the program would give the result i want but it doesnt . http://i.imgur.com/LqOczGM.jpg I input 2 , and the result should be "it is greater than or equal to one" could any ching give me improvement ? If i must use case command . thank you... (14 Replies)
Discussion started by: SSUUser
14 Replies

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

6. Shell Programming and Scripting

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,... (2 Replies)
Discussion started by: kasparov
2 Replies

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

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. Shell Programming and Scripting

can nested SQl be run in Unix Script?

can nested SQl be run in Unix Script? I tried some and found only simply sql(one select) can work well in unix script. (21 Replies)
Discussion started by: YoYo
21 Replies

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