case statement in UNIX scripting (ksh)


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers case statement in UNIX scripting (ksh)
# 1  
Old 03-03-2009
case statement in UNIX scripting (ksh)

Hi,
I have a script like below :

#!/bin/ksh
echo "Do you want to export all docs [yes or no]?"
read alld
echo "Do you want to export template or report only [yes or no]"
read temr

case [[$alld=="yes"] && [$temr=="yes"]]
#arguments
;;

case [[$alld=="no"] && [$temr=="yes"]]
#arguments
;;

case [[$alld== "yes"] && [$temr=="no"]]
#arguments
;;
done

Can someone debug my script and tell which parts are wrong? Because I've been getting syntax errors when I tried to run this script. Any feedback appreciated so much. Thanks Smilie
# 2  
Old 03-03-2009
Code:
read alld?"Do you want to export all docs [yes or no]? "

read temr?"Do you want to export template or report only [yes or no]? "

if [ $alld = "yes" -a $temr = "yes" ]
then
    echo "yes yes"
elif [ $alld = "no" -a $temr = "yes" ]
then
    echo "no yes"
elif [ $alld = "no" -a $temr = "no" ]
then
    echo "no no"
else
    echo "$alld $temr"
fi

# 3  
Old 03-03-2009
replace the == by =. Then enclose the double quotes for $alld.

Then instead of Case use the If statement.

i.e if [ "${alld}" = "yes" && "${temr}" = "yes"]; then
<arguments>
elif......

Try to implement like this...


# 4  
Old 03-03-2009
Quote:
Originally Posted by fpmurphy
Code:
read alld?"Do you want to export all docs [yes or no]? "

read temr?"Do you want to export template or report only [yes or no]? "

if [ $alld = "yes" -a $temr = "yes" ]
then
    echo "yes yes"
elif [ $alld = "no" -a $temr = "yes" ]
then
    echo "no yes"
elif [ $alld = "no" -a $temr = "no" ]
then
    echo "no no"
else
    echo "$alld $temr"
fi

hi fpmurphy, may i know which shell is this? i tried to do this in ksh but i got error
# 5  
Old 03-03-2009
Quote:
Originally Posted by sivakumar.rj
replace the == by =. Then enclose the double quotes for $alld.

Then instead of Case use the If statement.

i.e if [ "${alld}" = "yes" && "${temr}" = "yes"]; then
<arguments>
elif......

Try to implement like this...



hi sivakumar,

yes u are right, i think it's not gonna work if i use case statement. i will try to use the if statement now. thanks for your feedback Smilie
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell scripting with case statement

Foe example we have three environments int,qa and prod.Each environment has some number of servers. int=Server1,Server2,Server3 qa=Server4,Server5,Server6 prod=Server7,Server8,Server9 echo "Enter the Environment i.e int,qa,prod" read env case $env in int) ## Need command where all the... (9 Replies)
Discussion started by: nareshreddy443
9 Replies

2. Shell Programming and Scripting

ksh case statement issue

Hi. I wrote the following case statement to replace a series of 'ELIF' statements as it looks better and is easier to maintain. However, for some reason the commands don't fully work in this format. Take option 1. It should call a script that runs in the background but it doesn't work. Can anyone... (3 Replies)
Discussion started by: user052009
3 Replies

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

4. Shell Programming and Scripting

Menu and case statement scripting

hi all i am trying to get help with writing a script using case statement to display menu as 1) Authentication log 2) System log 3) Messages 4) Dmesg 5) Boot log Q) Exit When selecting the menu by 1 or 2 or 3 o 4 or 5, it should display the last 10 lines of the log files, if... (3 Replies)
Discussion started by: renegade11
3 Replies

5. Shell Programming and Scripting

Use case insensitive variable in ksh shell scripting using sed or awk

I am using a variable called $variable in a pattern search to print from a starting variable to a constant value. the variable search should be case in sensitive. i tired using Ip at the end in the below command. but in ksh it is not working. sed -n "/$variable/,/constant/p" file i also... (11 Replies)
Discussion started by: johnjs
11 Replies

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

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

8. Shell Programming and Scripting

Using an array with a case statement in KSH

Hi, I'm really new ro shell scripting (actually any kind of programming) and am pretty sure I'm making a pretty basic error here but I can't for the life of me figure it out. What I'm trying to do is get an array working with a case statement in a KSH script. The code is as follows: ... (3 Replies)
Discussion started by: SReilly
3 Replies

9. Shell Programming and Scripting

ksh "case" statement question

Hi I have the following case statement: case $larg in *_* ) a=${larg%_*}; b=${larg#*_}; ;; *^* ) a=${larg%^*}; b=${larg#*^}; ;; esac I cannot figure out what *_* and *^* stand for... Also what a=${larg%_*}; b=${larg#*_}; and a=${larg%^*}; b=${larg#*^}; ... (1 Reply)
Discussion started by: aoussenko
1 Replies

10. Shell Programming and Scripting

ksh case statement

I am trying to write a ksh script using the case statement to select certain directories to remove. The directories that I am looking for are in the following format 2008-10-10. I want to exclude all other files/directories that contain anything other the 4 digit year,a dash, 2 digit month, a... (2 Replies)
Discussion started by: dgilc
2 Replies
Login or Register to Ask a Question