bash similar to choice in cmd code example
Example 1: bash similiar to choice in cmd
#!/bin/bash
echo "select the operation ************"
echo " 1)operation 1"
echo " 2)operation 2"
echo " 3)operation 3"
echo " 4)operation 4"
read n
case $n in
1) echo "You chose Option 1";;
2) echo "You chose Option 2";;
3) echo "You chose Option 3";;
4) echo "You chose Option 4";;
*) echo "invalid option";;
esac
Example 2: bash similiar to choice in cmd
dialog --clear --backtitle "Backtitle here" --title "Title here" --menu "Choose one of the following options:" 15 40 4 \
1 "Option 1" \
2 "Option 2" \
3 "Option 3"
Example 3: bash similiar to choice in cmd
#!/bin/bash
clear
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