title: in a bash script that uses zenity --progress progress bar reading from a pipe, how to safely kill the piped process?
body: <p>I am displaying a command progress in a bash script. The command output is piped to zenity --progress and can eventually run for a long time. I want to abort it (kill that command) if I cancel the zenity dialog:</p>
  
  <pre><code>( echo 0; command; echo 100 ) | if ! zenity --progress
                                  then DO_SOMETHING_TO_KILL_command
                                  fi
  </code></pre>
  
  <p>All the solutions I have found either:</p>
  
  <ol>
  <li><p>generically kill "command" with pgrep, pidof, pkill, killall, etc. This is not what I want since there might be many such "command" running.</p></li>
  <li><p>create a fifo to output the PID of "command" (command &amp; echo $! >some_fifo; wait) and then read from it after the pipe.</p></li>
  </ol>
  
  <p>Solution 2. does what I want, but in an overcomplicated way (see e.g. an example <a href="http://forum.ubuntu-fr.org/viewtopic.php?pid=6995391#p6995391" rel="nofollow">here</a> (in French)). I want to avoid fifos or temp files if possible. It seems as if it could be done with an output redirection to a file descriptor at most, but I cannot figure exactly how.</p>
  
  <p>Note: command substitution for the whole group with redirection e.g., $( ( ... command&amp; echo >&amp;3 ... | zenity --progress ) 3>&amp;1 ) -- which is a generic soution in cases of this type -- does not work here because the $(...) waits until the whole subshell is completed.</p>