I\'m using a bash script menu like this:
#!/bin/bash
PS3=\'Please enter your choice: \'
options=(\"Option 1\" \"Option 2\" \"Option3\" \"Quit\")
select opt i
You can also do something like:
#!/bin/bash
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 3"
;;
"Quit")
break
;;
*) echo invalid option;;
esac
counter=1
SAVEIFS=$IFS
IFS=$(echo -en "\n\b") # we set another delimiter, see also: https://www.cyberciti.biz/tips/handling-filenames-with-spaces-in-bash.html
for i in ${options[@]};
do
echo $counter')' $i
let 'counter+=1'
done
IFS=$SAVEIFS
done