Bash Menu using zenity


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Bash Menu using zenity
# 1  
Old 10-08-2018
Bash Menu using zenity

Hi, I'm new to bash, and have an example menu script using Zenity. It works fine if the user enters A B or C, but if the user enters nothing, I can only figure out how to exit the script. How do I get the menu to reappear if no input is selected?

The script is:

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

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

    case "$opt" in
    "${options[0]}" ) select="A";;
    "${options[1]}" ) select="B";;
    "${options[2]}" ) select="C";;
#    *) zenity --error --text="Invalid option, "OK" to exit" && exit 1;;
    esac

#       if $select = "A" ;then break ;fi
        if zenity --question --text=" $select" ; then break ;fi


done > /dev/null 2>&1

Thanks fro any help.
This User Gave Thanks to allen11 For This Post:
# 2  
Old 10-08-2018
Try uncommenting the following line and change :
Code:
#    *) zenity --error --text="Invalid option, "OK" to request input again" && continue

This way, if any input is given besides the options specified, a while loop will start again.
Or if you just press OK in zenity without selection, error will appear, and upon clicking ok again, the menu will be restarted.

Hope that helps
Regards.
This User Gave Thanks to Peasant For This Post:
# 3  
Old 10-08-2018
Thank you Peasant, much appreciated. Just what I needed to know.
regards
Allen
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bash menu item counter

We have a simple menu with prompt of menu numbers to user. It is still under construction. Is there a way to "count" the menu choices so the prompt maximum count can be changed dynamically? See attached TODO note in code read_options(){ local choice # the... (7 Replies)
Discussion started by: annacreek
7 Replies

2. Shell Programming and Scripting

[bash] Zenity loop (raspbian)

Hello folks, I have created a GUI but i face some issue with the loop either i am stuck in the loop or it close the program In the code below it work fine for the "go to menu" if i press cancel i go back to the main menu but for "test" i m stuck in the menu Appreciate some help :/... (13 Replies)
Discussion started by: flammeur
13 Replies

3. Open Source

Bash menu not running

The perl command is not executing? I am trying to run the .pl in my cygwin home directory (C:\cygwin\home\cmccabe) using ${id}.txt.hg19_multianno.txt (located in the annovar directory) as the input file to be formatted and $FILENAME is the output file to be saved. The .pl is attached as... (8 Replies)
Discussion started by: cmccabe
8 Replies

4. Shell Programming and Scripting

Bash menu opens and closes

Ever since I added these two code blocks to my bash menu it just opens and closes right away. I use a batch file that worked fine until these codes were added and I am not sure what is wrong. Basically, what I am trying to do in the additional section is if the answer is "Y" then it goes back... (13 Replies)
Discussion started by: cmccabe
13 Replies

5. Shell Programming and Scripting

Bash Script - Whiptail Menu Help!

Hello, Been trying to build a menu with whiptail lately. However, my code doesn't seems to be working even though when i compared to other similar code they looks the same. #!/bin/bash clear whiptail --msgbox "Entering networking sub-menu" 20 78 whiptail --title Networking --menu... (8 Replies)
Discussion started by: malfolozy
8 Replies

6. UNIX for Dummies Questions & Answers

Simple bash script menu

Dear Sir, May I know how do I go about adding the following feature into the script below: When user enter values other than 1,2,3,4, a) Message “Wrong entry !!! Pls select 1,2,3 or 4” is displayed b) The screen is cleared again and the menu is displayed. #!/bin/bash clear var=1... (2 Replies)
Discussion started by: fusetrips
2 Replies

7. Shell Programming and Scripting

get chosen value from bash menu

Hi again :) This is just a sample whiptail menu. Works great, but have been trying to get the chosen value into a variable but failing pretty bad...its ther but unsure how to echo it out when needed #! /bin/bash #This is the menu whiptail --title "Menu example" --menu "Choose an... (9 Replies)
Discussion started by: olearydc
9 Replies

8. Shell Programming and Scripting

Help regarding a bash menu script

Greetings all, I'm having some trouble writing a menu drive bash script, actually coding the menu part was not difficult however its a problem with a menu option I'm having trouble with. My menu has 5 options, when the user selects the second option, they are then prompted to enter a number from... (5 Replies)
Discussion started by: Vitrophyre
5 Replies

9. Shell Programming and Scripting

Bash menu script

I have a main menu quit=n while do clear echo echo "1. General system information" echo "2. Hardware utilisation information" echo "3. File management" echo "4. User information" echo "5. Information on network connectivity" echo "6. Information on processes" echo "Q.Quit" ... (3 Replies)
Discussion started by: AngelFlesh
3 Replies

10. Shell Programming and Scripting

Zenity Menu

I have some troubles with zenity and menu. I seach for: MAIN MENU CHOICE 1 "do something" CHOICE 2 "do something 2" CHOICE 3 "do something 3" But then in "do someghing " when i click i want to return to the MAIN MENU So something like: while true; do ... (4 Replies)
Discussion started by: aspire
4 Replies
Login or Register to Ask a Question