Search
 
SCRIPT & CODE EXAMPLE
 

SHELL

bash similiar to choice in cmd

#!/bin/sh
show_menu(){
    normal=`echo "33[m"`
    menu=`echo "33[36m"` #Blue
    number=`echo "33[33m"` #yellow
    bgred=`echo "33[41m"`
    fgred=`echo "33[31m"`
    printf "
${menu}*********************************************${normal}
"
    printf "${menu}**${number} 1)${menu} Mount dropbox ${normal}
"
    printf "${menu}**${number} 2)${menu} Mount USB 500 Gig Drive ${normal}
"
    printf "${menu}**${number} 3)${menu} Restart Apache ${normal}
"
    printf "${menu}**${number} 4)${menu} ssh Frost TomCat Server ${normal}
"
    printf "${menu}**${number} 5)${menu} Some other commands${normal}
"
    printf "${menu}*********************************************${normal}
"
    printf "Please enter a menu option and enter or ${fgred}x to exit. ${normal}"
    read opt
}

option_picked(){
    msgcolor=`echo "33[01;31m"` # bold red
    normal=`echo "33[00;00m"` # normal white
    message=${@:-"${normal}Error: No message passed"}
    printf "${msgcolor}${message}${normal}
"
}

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/; #The 3 terabyte";
            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;
        ;;
        
)exit;
        ;;
        *)clear;
            option_picked "Pick an option from the menu";
            show_menu;
        ;;
      esac
    fi
done
Comment

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;;
        *) 
        #handle no option value
        echo "invalid option $REPLY";;
    esac
done
Comment

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"
Comment

bash similiar to choice in cmd

#!/bin/bash

HEIGHT=15
WIDTH=40
CHOICE_HEIGHT=4
BACKTITLE="Backtitle here"
TITLE="Title here"
MENU="Choose one of the following options:"

OPTIONS=(1 "Option 1"
         2 "Option 2"
         3 "Option 3")

CHOICE=$(dialog --clear 
                --backtitle "$BACKTITLE" 
                --title "$TITLE" 
                --menu "$MENU" 
                $HEIGHT $WIDTH $CHOICE_HEIGHT 
                "${OPTIONS[@]}" 
                2>&1 >/dev/tty)

clear
case $CHOICE in
        1)
            echo "You chose Option 1"
            ;;
        2)
            echo "You chose Option 2"
            ;;
        3)
            echo "You chose Option 3"
            ;;
esac
Comment

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
Comment

bash similiar to choice in cmd

#! /bin/bash

selection=$(zenity --list "Option 1" "Option 2" "Option 3" --column="" --text="Text above column(s)" --title="My menu")

case "$selection" in
"Option 1")zenity --info --text="Do something here for No1";;
"Option 2")zenity --info --text="Do something here for No2";;
"Option 3")zenity --info --text="Do something here for No3";;
esac
Comment

bash similiar to choice in cmd

#/bin/bash
# by oToGamez
# www.pro-toolz.net

      E='echo -e';e='echo -en';trap "R;exit" 2
    ESC=$( $e "e")
   TPUT(){ $e "e[${1};${2}H";}
  CLEAR(){ $e "ec";}
  CIVIS(){ $e "e[?25l";}
   DRAW(){ $e "e%@e(0";}
  WRITE(){ $e "e(B";}
   MARK(){ $e "e[7m";}
 UNMARK(){ $e "e[27m";}
      R(){ CLEAR ;stty sane;$e "ece[37;44me[J";};
   HEAD(){ DRAW
           for each in $(seq 1 13);do
           $E "   x                                          x"
           done
           WRITE;MARK;TPUT 1 5
           $E "BASH SELECTION MENU                       ";UNMARK;}
           i=0; CLEAR; CIVIS;NULL=/dev/null
   FOOT(){ MARK;TPUT 13 5
           printf "ENTER - SELECT,NEXT                       ";UNMARK;}
  ARROW(){ read -s -n3 key 2>/dev/null >&2
           if [[ $key = $ESC[A ]];then echo up;fi
           if [[ $key = $ESC[B ]];then echo dn;fi;}
     M0(){ TPUT  4 20; $e "Login info";}
     M1(){ TPUT  5 20; $e "Network";}
     M2(){ TPUT  6 20; $e "Disk";}
     M3(){ TPUT  7 20; $e "Routing";}
     M4(){ TPUT  8 20; $e "Time";}
     M5(){ TPUT  9 20; $e "ABOUT  ";}
     M6(){ TPUT 10 20; $e "EXIT   ";}
      LM=6
   MENU(){ for each in $(seq 0 $LM);do M${each};done;}
    POS(){ if [[ $cur == up ]];then ((i--));fi
           if [[ $cur == dn ]];then ((i++));fi
           if [[ $i -lt 0   ]];then i=$LM;fi
           if [[ $i -gt $LM ]];then i=0;fi;}
REFRESH(){ after=$((i+1)); before=$((i-1))
           if [[ $before -lt 0  ]];then before=$LM;fi
           if [[ $after -gt $LM ]];then after=0;fi
           if [[ $j -lt $i      ]];then UNMARK;M$before;else UNMARK;M$after;fi
           if [[ $after -eq 0 ]] || [ $before -eq $LM ];then
           UNMARK; M$before; M$after;fi;j=$i;UNMARK;M$before;M$after;}
   INIT(){ R;HEAD;FOOT;MENU;}
     SC(){ REFRESH;MARK;$S;$b;cur=`ARROW`;}
     ES(){ MARK;$e "ENTER = main menu ";$b;read;INIT;};INIT
  while [[ "$O" != " " ]]; do case $i in
        0) S=M0;SC;if [[ $cur == "" ]];then R;$e "
$(w        )
";ES;fi;;
        1) S=M1;SC;if [[ $cur == "" ]];then R;$e "
$(ifconfig )
";ES;fi;;
        2) S=M2;SC;if [[ $cur == "" ]];then R;$e "
$(df -h    )
";ES;fi;;
        3) S=M3;SC;if [[ $cur == "" ]];then R;$e "
$(route -n )
";ES;fi;;
        4) S=M4;SC;if [[ $cur == "" ]];then R;$e "
$(date     )
";ES;fi;;
        5) S=M5;SC;if [[ $cur == "" ]];then R;$e "
$($e by oTo)
";ES;fi;;
        6) S=M6;SC;if [[ $cur == "" ]];then R;exit 0;fi;;
 esac;POS;done
Comment

bash similiar to choice in cmd

title="Select example"
prompt="Pick an option:"
options=("A" "B" "C")

echo "$title"
PS3="$prompt "
select opt in "${options[@]}" "Quit"; do 

    case "$REPLY" in

    1 ) echo "You picked $opt which is option $REPLY";;
    2 ) echo "You picked $opt which is option $REPLY";;
    3 ) echo "You picked $opt which is option $REPLY";;

    $(( ${#options[@]}+1 )) ) echo "Goodbye!"; break;;
    *) echo "Invalid option. Try another one.";continue;;

    esac

done


while opt=$(zenity --title="$title" --text="$prompt" --list 
                    --column="Options" "${options[@]}"); do

    case "$opt" in
    "${options[0]}" ) zenity --info --text="You picked $opt, option 1";;
    "${options[1]}" ) zenity --info --text="You picked $opt, option 2";;
    "${options[2]}" ) zenity --info --text="You picked $opt, option 3";;
    *) zenity --error --text="Invalid option. Try another one.";;
    esac

done
Comment

bash similiar to choice in cmd

read -n 1 -p "Would you like to exit, reboot, or shutdown? (E/r/s) " ans;

case $ans in
    r|R)
        sudo reboot;;
    s|S)
        sudo poweroff;;
    *)
        exit;;
esac
Comment

PREVIOUS NEXT
Code Example
Shell :: overwrite a file name character in linux 
Shell :: append filename at the beggining linux 
Shell :: ping command output to null in linux 
Shell :: hwo to run a .bat file on a remote windows host 
Shell :: @capacitor-community/fcm 
Shell :: how to reset password for ubuntu GCP instance 
Shell :: kubernetes cert kubeconfig 
Shell :: como agreagar archivo a .gitignore y eliminarlo del repositorio 
Shell :: ubuntu switch between windows shortcut 
Shell :: resolve symlinks mac 
Shell :: curl command to create a saved search for a user in splunk 
Shell :: linux search last commands 
Shell :: bash 
Shell :: Linux Terminal has lost its colours 
Shell :: reiniciar camera macOs command line 
Shell :: make[1]: [scripts/Makefile.lib:196: scripts/kconfig/zconf.tab.c] Error 127 make: *** [Makefile:534: bb.org_defconfig] Error 2 root@192.168.4.89:/usr/src/linux-4.19.94-ti-rt-r61# 
Shell :: brew sh 
Shell :: 2 chaves ssh 
Shell :: how to start lightdm from command line 
Shell :: fix errors occurred during update in linux 
Shell :: tag a git stash with keyword 
Shell :: wasmtime 
Shell :: -d flag linux if 
Shell :: arangodb arangodump backup 
Shell :: docker image layer storage windows 
Shell :: bash find files and operator 
Shell :: disable monitor on boot linux 
Shell :: libexpat fedora 
Shell :: The lsb_release command ubuntu faq 
Shell :: Configure NFS Write Performance 
ADD CONTENT
Topic
Content
Source link
Name
5+5 =