batch choice command code example
Example 1: bash similiar to choice in cmd
#!/bin/sh
show_menu(){
normal=`echo "\033[m"`
menu=`echo "\033[36m"`
number=`echo "\033[33m"`
bgred=`echo "\033[41m"`
fgred=`echo "\033[31m"`
printf "\n${menu}*********************************************${normal}\n"
printf "${menu}**${number} 1)${menu} Mount dropbox ${normal}\n"
printf "${menu}**${number} 2)${menu} Mount USB 500 Gig Drive ${normal}\n"
printf "${menu}**${number} 3)${menu} Restart Apache ${normal}\n"
printf "${menu}**${number} 4)${menu} ssh Frost TomCat Server ${normal}\n"
printf "${menu}**${number} 5)${menu} Some other commands${normal}\n"
printf "${menu}*********************************************${normal}\n"
printf "Please enter a menu option and enter or ${fgred}x to exit. ${normal}"
read opt
}
option_picked(){
msgcolor=`echo "\033[01;31m"`
normal=`echo "\033[00;00m"`
message=${@:-"${normal}Error: No message passed"}
printf "${msgcolor}${message}${normal}\n"
}
clear
show_menu
while [ $opt != '' ]
do
if [ $opt = '' ]; then
exit;
else
case $opt in
1) clear;
option_picked "Option 1 Picked";
printf "sudo mount /dev/sdh1 /mnt/DropBox/;
show_menu;
;;
2) clear;
option_picked "Option 2 Picked";
printf "sudo mount /dev/sdi1 /mnt/usbDrive; #The 500 gig drive";
show_menu;
;;
3) clear;
option_picked "Option 3 Picked";
printf "sudo service apache2 restart";
show_menu;
;;
4) clear;
option_picked "Option 4 Picked";
printf "ssh lmesser@ -p 2010";
show_menu;
;;
x)exit;
;;
\n)exit;
;;
*)clear;
option_picked "Pick an option from the menu";
show_menu;
;;
esac
fi
done
Example 2: 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