use strings in case statement options


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting use strings in case statement options
# 1  
Old 07-17-2009
Question use strings in case statement options

I iterate in string list well but when I try to add a case statement in order to wrap the string value in a more accurate message I faced different problems.

#Code starts
ST_CODES="CN CU BU CQ LE"
for ST_CODE in $ST_CODES
do
#echo $ST_CODE
CODE="$ST_CODE""\n"
case "$CODE" in
"CN") echo " Countries " ;;
"CU") echo " Currencies" ;;
"BU") echo " Business Units";;
"CQ") echo "Currency Quotations";;
"LE") echo "Leagal Enities";;
esac
done
#Code finish

Thanks in advance!
# 2  
Old 07-17-2009
When you ask question, try to be more precise. What kind of problems have you been facing? Your code doesn't produce any errors. Each time the 'CODE' variable is tested in 'case' construct, there is no match, because of extra newline character appended to 'CODE' variable.
# 3  
Old 07-19-2009
1st you add newline to the variable
CODE="$ST_CODE""\n"
Why ?



if you don't do that then your case works fine.
CODE="$ST_CODE" is enough
# 4  
Old 07-19-2009
Computer thanks to both

Thanks fellows!

Now work fine. In the first script I didn't use the newline character but I introduced a control character.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Read Strings in as options to switches

I have a script using getops with -a -t -l as potential switches, based on the switches used, it will set the respective variable value which will cause the routine/function to run. I need to also pass a string with the switch that will get parsed by the function. example ./myscript -a... (8 Replies)
Discussion started by: glev2005
8 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

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

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

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

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

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

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

9. Shell Programming and Scripting

stacking case options

possible to stack case commands ? I get an error, s. comments below select choice in search delete quit do case $choice in search) select option in title director year do case $option in title) ..... break ;; ... (2 Replies)
Discussion started by: forever_49ers
2 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