having some trouble in case statement


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting having some trouble in case statement
# 1  
Old 07-02-2012
having some trouble in case statement

Hi All,

I have script which will take the parameter as
PNLYYYYMMDD/PNL
or PNL-AMDYYYYYMMDD/PNL-AMD
now based on YYYYMMDD my script will parse and do some logic within

my case statement looks like below

Code:
case `echo $1 | tr '[:upper:]' '[:lower:]'`
in
pnl*) do some logic;;
pnl-amd*) do some logic;;
*);;
esac

now if my script takes the parameter as PNLYYYYMMDD or PNL it works fine
but if I'm passing parameter like pnl-amdYYYYYMMD
then it's taking pnl* case and trying to execute it's logic not the pnl-amd* one.

So how can I instruct case statement to follow pnl-amd logic when I'm passing pnl-amd as parameter???
# 2  
Old 07-02-2012
Try flipping the two case statement entries around. The first case is inclusive of the second, so it will gobble up all "pnl-amd"'s
# 3  
Old 07-02-2012
hey Scrutinizer, I know I need to switch the postion in order to work.
But the logic for each case is a huge one, so I don;t want to make everything goes bad.
So intsead I came up with this one,
Code:
case `echo $1 | tr '[:upper:]' '[:lower:]'`
in
pnl[^-]*) do some logic;;
pnl-amd*) do some logic;;
*);;
esac

which is working fine, atleast.....now
Cheers!!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

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

2. Shell Programming and Scripting

Case Statement

Hey, guys I really need some help with a project. "Write a shell program that examines the command line arguments, counts and collects the number of options. Basically it has to collect and count the arguments that start with a "-" and the one's that don't start with a - I know I have to use... (2 Replies)
Discussion started by: sk192010`
2 Replies

3. Shell Programming and Scripting

Trouble in getting user input while using CASE statement in UNIX

i want to get user input like this please tell which option to chose 1. mango 2. tango 3. rango if user chooses mango then it should execute a set of statements and again ask like this what do you want to do 1.add 2.subtract 3.exit when i choose exit it should goto my previous menu... (4 Replies)
Discussion started by: s.deepak
4 Replies

4. Shell Programming and Scripting

!!VERY URGENT!! Trouble in getting user input, while using under CASE statement in UNIX

i want to get user input like this please tell which option to chose 1. mango 2. tango 3. rango if user chooses mango then it should execute a set of statements and again ask like this what do you want to do 1.add 2.subtract 3.exit when i choose exit it should goto my previous... (1 Reply)
Discussion started by: s.deepak
1 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

hi all i'm writing a script and in it i need to prompt the user if the entered value is correct or not ,i wrote the following and its not working ,its executing the script even if i enter Y/N pls any help is appreciated echo "\nAre you sure you entered the right Destination Environment? y :... (5 Replies)
Discussion started by: bkan77
5 Replies

10. 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
Login or Register to Ask a Question