Tuesday, April 15, 2008

bash select menu example

Here is a simple bash select menu example:
(Thanks to my friend)

#!/bin/bash
# Date: 15.04.08
# Author: bash@roshankarki.com.mnp
# Purpose: Usage of select

PS3='Please enter your choice'
LIST="choice1 choice2 END"
select OPT in $LIST
do
if [ $OPT = "choice1" ] &> /dev/null
then
echo you chose choice1
elif [ $OPT = "choice2" ] &> /dev/null
then
echo you chose choice2
elif [ $OPT = "END" ] &> /dev/null
then
exit 0
fi
done
#END

6 comments:

  1. very useful. It saves our time.

    ReplyDelete
  2. This doesn't work. Why do you post incorrect examples?

    ReplyDelete
  3. I'm astonished by your comment. Can you specify what makes you think this doesn't work or can you provide the error if you have tried it in bash.

    ReplyDelete
  4. I did one bash men script with cat

    http://unstableme.blogspot.com/2008/06/bash-script-menu.html

    // Jadu

    ReplyDelete
  5. Thank you very much. The select opt in $list;do;done method is very easy to implement.

    ReplyDelete
  6. This works just fine. Thank You

    ReplyDelete

Comments are moderated. No spam please.