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:

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.

1 Like

Try uncommenting the following line and change :

#    *) 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.

1 Like

Thank you Peasant, much appreciated. Just what I needed to know.
regards
Allen