Bash select menu

From thelinuxwiki
Jump to: navigation, search

Example select menu

 #!/bin/bash
 OPTIONS="Hello Break Exit"
 select opt in $OPTIONS; do
   if [ "$opt" = "Exit" ]; then
     echo "exiting script with command exit" 
     exit 
   elif [ "$opt" = "Hello" ]; then
     echo Hello World
     break
   elif [ "$opt" = "Break" ]; then
     echo "you chose to Break select menu and continue script"
     break
   else
     echo bad option, try again 
   fi
 done
 #
 echo "end of script.  this is printed unless you choose Exit from the menu which executes the exit command and terminates the script at that point."