Sample Header Ad - 728x90

How does a Zenity progress dialog's cancel button function?

1 vote
2 answers
6034 views
While trying to make the Cancel button on a Zenity --progress window work for my scripts I've realized I don't understand how the Cancel button works at all in the example given on the Zenity Manual page: https://help.gnome.org/users/zenity/stable/progress.html.en #!/bin/sh ( echo "10" ; sleep 1 echo "# Updating mail logs" ; sleep 1 echo "20" ; sleep 1 echo "# Resetting cron jobs" ; sleep 1 echo "50" ; sleep 1 echo "This line will just be ignored" ; sleep 1 echo "75" ; sleep 1 echo "# Rebooting system" ; sleep 1 echo "100" ; sleep 1 ) | zenity --progress \ --title="Update System Logs" \ --text="Scanning mail logs..." \ --percentage=0 if [ "$?" = -1 ] ; then zenity --error \ --text="Update canceled." fi When that script is run, why does the process stop when the Cancel button is pushed when there is no exit or break or any other command visible? I thought Zenity was just a program to display graphical interfaces and return exit codes that can be used to launch the actual commands desired (like exit if cancelled, etc), but it seems like Zenity must be doing something much more complicated because there doesn't seem to be any reason for the commands in the example to actually stop when the button is pressed. Is Zenity doing something more complicated, or am I misunderstanding something? I am new to bash/sh scripting so it seems like I'm probably misunderstanding. If it's just a complex function unique to Zenity then a full technical description of how it works is not necessary; just enough of an explanation so it can be used reliably is what I would like. Thank you. (I'd like to also ask why this example from the official manual **does not actually work** [on Ubuntu 14.04] because no --error Zenity window is ever shown, but I don't think StackExchange likes joint questions, so nevermind that unless it's related to how I might be misunderstanding.) Related post: https://unix.stackexchange.com/questions/42082/terminate-script-using-zenity-progress-bar (does not answer my question because the top answer there said to use --auto-kill when in this example the process is cancelled without using --auto-kill
Asked by InverseTelecine (193 rep)
Feb 7, 2016, 05:30 PM
Last activity: Aug 13, 2022, 01:32 AM