Copyright © 2008-2017, dave - Code samples on Dave's Brain is licensed under the Creative Commons Attribution 2.5 License. However other material, including English text has all rights reserved.
Date: 2012sep16 Language: Bash OS: Linux Q. How can I do a simple menu in bash? A. Put the read command into a while loop like this:# Use echo to display the choices... echo echo "Select program to run" echo echo " 1. Program One" echo " 2. Program Two" echo " 3. Program Three" echo -n "> " # Loop until the user enters something valid... while :; do # Read one character and don't echo it... read -s -n 1 c if [[ $c == 1 ]]; then echo $c # Run program one break fi if [[ $c == 2 ]]; then echo $c # Run program two break fi if [[ $c == 3 ]]; then echo $c # Run program three break fi done
Add a commentSign in to add a comment