Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm very new to programming on Ubuntu. And I'm trying to do a simple bash script.

I have a select menu working but I want the choices made in that to go into a number of if statements, corresponding to the choices made.

For example, here's the pseudo code:

Choose from the following 

a selected 

if a is selected 
run this script 

if b selected 
run this script

if c selected 
run this script

How do I get the choice passed on into the relevant if statement?

All of this has to be run from the one script. This is probably very simple but I'm new to this and struggling my way through it.

share|improve this question

You'd use a case statement:

var=... your menu select code ...

case "$var" in
    a )
        script_a ;;
    b )
        script_b ;;
    c )
        script_c ;;
esac have a load more examples.

share|improve this answer
Bash is so weird... – Seth Mar 29 '13 at 15:43
So is Oli, knowing all these things... – don.joey Mar 29 '13 at 15:55

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.