title: error handling with chained commands (pipes) in a bash script?
body: <p>i currently wonder how to do error handling for chained commands. the following is just an example to easy demonstrate my problem:</p>
  
  <pre><code>cat file | gzip &gt;/tmp/test
  </code></pre>
  
  <p>if <em>cat</em> fails (because for example <em>file</em> is missing), <em>gzip</em> is still executed and therefore the last stored exit code in <em>$?</em> is <em>0</em>. <em>set -e</em> won't help either in this case.</p>
  
  <p>i wonder what's the best solution for this?</p>
  
  <p>thanks!</p>