Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Usually this would be a question about how to pass data from a subprocess to a main process, but maybe zenity has some extra quirks so please focus on zenity.


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..." \

# ... here main process continues (x)

Each step in practice can fail (there is more than just an echo -- tar, computing md5, zipping, unzipping, you name it), and I would like to set, for example, variable ERR to some message and quit the progress subprocess, and after that display content of ERR and quit for good.

The problem is, ERR is local variable, so I can break the subprocess, but nevertheless I cannot pass ERR outside. I cannot also display it locally, because the main script will continue anyway, unaware that the subprocess failed.

So the question is, how can I pass an error code, message, anything to the main process (continuing at the (x) point)?

Process substitution:

zenity --progress \
  --title="Update System Logs" \
  --text="Scanning mail logs..." \
  --percentage=0 < <(
echo "10" ; sleep 1
echo "# Updating mail logs" ; sleep 1

This didn't work for me too, i.e. ERR was not visible to the main script.

share|improve this question
up vote 4 down vote accepted

What you probably is want is PIPESTATUS (from man bash:)

An array variable (see Arrays below) containing a list of exit status 
values from the processes in the most-recently-executed foreground pipeline 
(which may contain only a single command).
share|improve this answer
Thank you, for my program this will do the trick. – greenoldman May 16 '12 at 20:53

I solved the problem as Fabian suggested (thank you again). However, I was not happy with the entire construction of the data flow. After all, it is Zenity which should monitor the progress of the work; I should not have to bend my entire program just to make it happy.

So, I changed the entire workflow. First I create a named pipe in order to communicate the progress to Zenity, and then Zenity works as it should (as a monitor). So I call:

(tail -f my_named_pipe) | zenity .... &

and when I want to set a label or progress I simply call

echo "# We are cruising..." > my_named_pipe

If I am done with progress I send "100" to Zenity. This allows my main script to work in a linear manner, without worrying about passing data from a subprocess, because there is no subprocess now.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.