I copied the bash script from this site:
https://askubuntu.com/questions/1705/how-can-i-create-a-select-menu-in-a-shell-script
I INSERTED SPACES TO KEEP DU FROM DISPLAYING SMILIES!!!
NEVER PUT A CLOSE PAREN AFTER A DOUBLE QUOTE.
YOU GET THIS "
And DU doesn't honor indents. It's not a code site.
Question:
I'm creating a simple bash script and I want to create a select menu in it, like this:
$./script
echo "Choose your option:"
1) Option 1
2) Option 2
3) Option 3
4) Quit
Answer 1
#!/bin/bash
# Bash Menu Script Example
PS3='Please enter your choice: '
options=("Option 1" "Option 2" "Option 3" "Quit" )
select opt in "${options[@]}"
do
case $opt in
"Option 1" )
echo "you chose choice 1"
;;
"Option 2" )
echo "you chose choice 2"
;;
"Option 3" )
echo "you chose choice $REPLY which is $opt"
;;
"Quit" )
break
;;
*) echo "invalid option $REPLY";;
esac
done
Looks easy enough.
Mac version (tested and works)
#!/bin/bash
# Bash Menu Script Example
PS3='Please enter your choice: '
options=("Clock" "Notes" "Stickies" "Quit" )
select opt in "${options[@]}"
do
case $opt in
"Clock" )
open -a Clock &
;;
"Notes" )
open -a Notes &
;;
"Stickies" )
open -a Stickies &
;;
"Quit" )
break
;;
*) echo "invalid option $REPLY";;
esac
done
It works with the space between the " and the )
And prints on DU
One could get fancier. I didn't even read the other answers.
Bash is essential to computer use!
You BASH the computer or the computer BASHES you.
For anything more deluxe, use Tcl and Tk.
They are interpreted and have a GUI toolkit (Tk)
Active State has an installer. Free
https://www.activestate.com/products/tcl/
Note on the above.
I put that code into a script, called it do
chmod +x do
./do
Anyway, here's a screenshot FYI to show the indentation (for looks in Bash. Indentation counts in Python)