choose y or n


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting choose y or n
# 1  
Old 02-12-2011
choose y or n

Hi,
I have written a choice based shell script some thing like this:

if (y)
execute code
....
fi

else if(n)
terminating


the problem with the above scripting is it will work as far as the options are y or n.
but i want to reiterate the same code when the user inputs something else other than y or n.
please can some one tell me How can i achieve this in shell script.
# 2  
Old 02-12-2011

Use elif:
Code:
if [ "$x" = y ]
then
   : do y
elif [ "$x" = n ]
then
   : do n
elif [ "$x" = q ]
then
   : do q
fi

or a case statement:
Code:
case $x in
     y) : do y
        ;;
     n) : do n
        ;;
     q) : do q
        ;;
esac

This User Gave Thanks to cfajohnson For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Which Product to Choose?

Okay, I have an Asus A8NSLI board with an Athlon 64 and I dunno, maybe 8gig Ram and Windows has crashed for the last time so I've finally had enough and I'll make it a Unix machine. I have a new 1Tera drive and I'm all set to go. Which brand of Unix/Linux can you advise me to go for? The... (3 Replies)
Discussion started by: abrogard
3 Replies

2. UNIX for Dummies Questions & Answers

How to choose the RIGHT PID?

I can find a single PID and copy it to a variable (thanks to the forum), but I have a slightly tougher situation: When a user logs into our system, it creates 5 processes example: root 21160 3096 0 07:16 ? 00:00:00 sshd: cs113 cs113 21164 21160 0 07:16 ? 00:00:00... (3 Replies)
Discussion started by: Igrok
3 Replies

3. Programming

Choose compiler version

Hi, I'm new, here, and I'm searching for a simple solution for a simple problem. I'm working on RedHat 4.4.6-4 through a CentOS Virtual Machine and due to some reasons I must compile my C++ codes with these two different g++ versions: 4.4.6 and 4.2.2. The fact is that I should be able to... (4 Replies)
Discussion started by: Marcuss
4 Replies

4. Web Development

Which version of tomcat should i choose?

hello every body, i want to install tomcat but i want the latest stable version. I found the 7 version is latest but i found alot of minor versions from 7.0.6 to 7.0.32 and i don't know which one should i install. i have oracle 11 and want tomcat to communicate with it i will install tomcat... (4 Replies)
Discussion started by: maxim42
4 Replies

5. What is on Your Mind?

Which Tablet to Choose?

Currently in the process of looking for a tablet. Which one is best? Thanks Benjamin Mauerberger (9 Replies)
Discussion started by: hlinks12
9 Replies

6. Shell Programming and Scripting

how to choose random columns

Hello! Can anybody suggest about the fastest way of extracting "n" random columns from a very large file (tab separated) having thousands of columns, where n can be any specified number. Thanks! (10 Replies)
Discussion started by: mira
10 Replies

7. Shell Programming and Scripting

Choose a gateway according to IP with awk

Hello, I have to make a script shell with awk function to choose the gateway to apply according to a "IP". Ex: 10.121.66.125 10.121.63.122 10.122.68.122 If the adress is in network 10.121.66.x , i set Gateway=10.121.66.3 Or If the adress is in network 10.121.62.x , i set... (3 Replies)
Discussion started by: khalidou13
3 Replies

8. Programming

GCC: Choose my own linker

Hi, I do not use the default linker, and instead us another one and pass this argument -Wl,--dynamic-linker=<path to linker> to gcc when compiling. However, what happens if the linker is not under /lib and /lib64 and I am not able to create a symlink to the linker in /lib or /lib64 due to no... (2 Replies)
Discussion started by: Shompis
2 Replies
Login or Register to Ask a Question