5

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) 
b) 
c)

a selected 

if a is selected 
then 
run this script 
fi

if b selected 
then 
run this script
fi

if c selected 
then 
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.

7

You'd use a case statement:

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

case "$var" in
    a )
        script_a ;;
    b )
        script_b ;;
    c )
        script_c ;;
esac

tldp.org have a load more examples.

  • 2
    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 clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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