Score:1

How do I loop my fancy Bash Dialog menu?

ag flag

So here is what I have, and I am very happy with what I have so far, but I do want to add a loop so when a command has been executed, ask for a "ENTER" strike and it will send you back to the menu...

#!/bin/bash
cmd=(dialog --keep-tite --menu "Welcome to Ernie's Utility Menu v1.0:" 22 76 16)

options=(1  "Hide Connection"
         2  "Disconnect from VPN"
         3  "Status of Connection"
         4  "Update the system"
         5  "Clean up post update mess" 
         6  "Deep Clean (Trojans and malware)"
         7  "Speedometer (Bandwith Monitor)"
         8  "Bmon (Bandwith Monitor)"
         9  "Test Bandwith speed (up & down)"
         10 "Snow in the terminal"
        )

choices=$("${cmd[@]}" "${options[@]}" 2>&1 >/dev/tty)

for choice in $choices 
    do    
        case $choice in
        1)
            expressvpn connect
            ;;
        2)
            expressvpn disconnect
            ;;
        3)
            expressvpn status && nmcli dev wifi
            ;;
        4)
            sudo apt update && sudo apt upgrade -y #!//&& sudo apt-get dist-upgrade -y not sure if I want to do this part....
            ;;
        5)
            sudo apt update && sudo apt -f install && sudo dpkg --configure -a && sudo apt clean && sudo apt autoremove && sudo -k && exit
            ;;
        6)
            sudo chkrootkit -d && sudo rkhunter -c --rwo && sudo -k
            ;;
        7)
            speedometer -l  -r wlp2s0 -t lo -m $(( 1024 * 1024 * 3 / 2 ))
            ;;
        8)
            bmon
            ;;
        9)
            speedtest
            ;;
        10)
            ./snow.sh
            ;; 
    esac
done
Terrance avatar
id flag
One issue I can see with this loop and the answer below is that you don't have an exit. I would make the Option 11 for Exit. Then the case line would just be `11) exit;;` if you don't want to use Ctrl+C.
Erniemenendez avatar
ag flag
If you run this script, it has two options at the bottom, one is "OK" The otherone is "CANCEL" which terminates the script. Thank you for the info anyways!!!! I might use it on another script! EDIT: yes, you are right. "CANCEL" returns me to the menu, lol
Score:2
cn flag

At the end of the script add:

read -p "Hit enter to continue ..."
exec /bin/bash "$0" "$@"

the exec command will re-execute the script, re-using the current process.

Erniemenendez avatar
ag flag
SUPERB!!!! Now my script is complete!!! you Glenn Jackman are a genius!!! THANK YOU!!!
vanadium avatar
cn flag
I'd rather work with an infinite loop in the script, then include an option in the menu to exit (command: `exit`, or `break`)
Score:0
ag flag

SO, if someone is interested in recycle this menu... This is what my final product looks like;

#!/bin/bash
cmd=(dialog --keep-tite --menu "Welcome to Ernie's Utility Menu v1.0:" 22 76 16)

options=(1  "Hide Connection"
         2  "Disconnect from VPN"
         3  "Status of Connection"
         4  "Update the system"
         5  "Clean up post update mess" 
         6  "Deep Clean (Trojans and malware)"
         7  "Speedometer (Bandwith Monitor)"
         8  "Bmon (Bandwith Monitor)"
         9  "Test Bandwith speed (up & down)"
         10 "Snow in the terminal"
#         11 "exit"
        )

choices=$("${cmd[@]}" "${options[@]}" 2>&1 >/dev/tty)

for choice in $choices 
    do    
        case $choice in
        1)
            expressvpn connect
            ;;
        2)
            expressvpn disconnect
            ;;
        3)
            expressvpn status && nmcli dev wifi
            ;;
        4)
            sudo apt update && sudo apt upgrade -y #!//&& sudo apt-get dist-upgrade -y not sure if I want to do this part....
            ;;
        5)
            sudo apt update && sudo apt -f install && sudo dpkg --configure -a && sudo apt clean && sudo apt autoremove && sudo -k
            ;;
        6)
            sudo chkrootkit -d && sudo rkhunter -c --rwo && sudo -k
            ;;
        7)
            speedometer -l  -r wlp2s0 -t lo -m $(( 1024 * 1024 * 3 / 2 ))
            ;;
        8)
            bmon
            ;;
        9)
            speedtest
            ;;
        10)
            ./snow.sh
            ;;
         *)
            exit
      esac
read -p "Hit enter to continue ..."
exec /bin/bash "$0" "$@"
      done
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.