Mystery about Case Statement


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Mystery about Case Statement
# 1  
Old 02-17-2010
Mystery about Case Statement

Can I make use of two command variable in case statement

Code:
 case $2 $3 in

         stp)
            Firewall disabled
            echo " Changing the http Proxy configuration "
        ;;
         str)
            Firewall enabled
            echo " Setting right http Proxy configuration "
        ;;
         disable)
                Router disabled
                echo " Disabling the Device in few seconds "
        ;;
         enable)
                Router enabled
                echo " Enabling the Device in few seconds "
        ;;
        *)
                usage
                echo " Please check for correct Parameter from the Usage "
        ;;
esac

from above script :

$2 = Firewall Stopping or starting
$3 = Router stopping & starting

Instead i used all the other Shell parameters viz $# & $* & $- , it dint function properly. Do someone suggests me how can i go to have both the things work good.

My script performs any one of the Command Variable ,, even when i passed both simultaneously.

Thanks in Advance
# 2  
Old 02-17-2010
I think you should use two successive case statements.
# 3  
Old 02-17-2010
It doesn't get better - maybe stick with the thread where cfjohnson is trying to help you.

Edit:
This was not meant for frans' helpful post of course.

Last edited by zaxxon; 02-17-2010 at 10:36 AM..
# 4  
Old 02-17-2010
Thanks it worked for me !!
# 5  
Old 02-17-2010
Code:
for flag in "$2" "$3"
do
  case "$flag" in
         stp)
            Firewall disabled
            echo " Changing the http Proxy configuration "
        ;;
         str)
            Firewall enabled
            echo " Setting right http Proxy configuration "
        ;;
         disable)
                Router disabled
                echo " Disabling the Device in few seconds "
        ;;
         enable)
                Router enabled
                echo " Enabling the Device in few seconds "
        ;;
        *)
                usage
                echo " Please check for correct Parameter from the Usage "
        ;;
  esac
done

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Case statement help

Hi I am new to shell scripting, I wanted to make a shell script that has a case statement asking the user to select their city 1)london 2)tokyo 3) etc., I then want the users input to be stored in a variable and echoed out in another script; so for example if the user selects tokyo, tokyo city code... (2 Replies)
Discussion started by: scriptnewbie
2 Replies

2. Homework & Coursework Questions

Case Statement

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: Hey, guys I really need some help with a project. "Write a shell program that examines the command line... (8 Replies)
Discussion started by: sk192010`
8 Replies

3. Shell Programming and Scripting

Case statement

Hello, The standard case statement :- case "$1" in "IE0263") commands;; "IE0264") commands;; esac is it possible to have :- case "$1" in "IE0263" OR "IE0878") commands;; "IE0264") commands;; esac Thanks (4 Replies)
Discussion started by: jmahal
4 Replies

4. Shell Programming and Scripting

case statement

Hi, I am writing case statement to execute some finction, my requirement is once one of the case statement is executed again it has to prompt for the option. for script in `echo "$Script_Selected"` do case $script in 1) getNoOFActUsers ;; 2) moveServerrOORotation ;; ... (2 Replies)
Discussion started by: Satyak
2 Replies

5. Shell Programming and Scripting

help with case statement

I am writing a script to pull diskspace information from our servers. Here is the script that I wrote: #!/bin/ksh for host in `cat /oper/hosts/esc.misc` do ssh -q -o ConnectTimeout=10 operator@$host df -h|grep "/dev/" |egrep '8%|9%|100%' | awk '{print H " " "at " $5 " with " $4 "... (1 Reply)
Discussion started by: rkruck
1 Replies

6. UNIX for Dummies Questions & Answers

CASE statement

Hi, I am writing a bash shell script. My script has a few user defined parameters. When the script runs the first thing it does is make sure that these parameters are valid. One of the parameters is called YEAR. A valid input for YEAR can be 1997-2000. One way I have come up with to ensure... (3 Replies)
Discussion started by: msb65
3 Replies

7. Shell Programming and Scripting

case statement

Hi all, I think i'm asking a sqtupid question here.. i'm using case sttament, what is the syntax or symbol for "or"? I thought was || here a quick sample of my case statment echo "Would you like to update your detail ?" read response case $response in ... (2 Replies)
Discussion started by: c00kie88
2 Replies

8. UNIX for Dummies Questions & Answers

If or Case Statement

I want to write a program with the following variables: a=7000 b=24000 c=613.8 The user can enter two words: Vivid or Blue for example. The challenge is that the user might not want to write the words the way they appear. The user can write V or v or vivid or Vivid or write Blue or blue, or B,... (1 Reply)
Discussion started by: Ernst
1 Replies

9. Shell Programming and Scripting

Case Statement

Can anyone please tell me why this wont work! Thanks so much! #!/bin/sh for file do case $file in *.*.*) echo Cannot have more than 1 dot exit ;; *'**'*) echo Cannot have more than 1 asterisk exit ;; *'*'*|?.) echo this is a target (19 Replies)
Discussion started by: Zeta_Acosta
19 Replies

10. Shell Programming and Scripting

case statement

Hi all, is it possible to create a 'dynamic' case statement. ie select option in `ls` do case satement depending on results of the above `ls` done I hope I have explained this ok! Thanks Helen (1 Reply)
Discussion started by: Bab00shka
1 Replies
Login or Register to Ask a Question