title: bzip2 - Broken pipe
body: <p>I have the following code in my shell script:</p>
  
  <pre><code>bzip2 -dc $filename | head -10 &gt; $output
  </code></pre>
  
  <p>Sometimes I'm getting this error (debug output enabled):</p>
  
  <pre><code>+ head -10
  + bzip2 -dc mylog.bz2
  
  bzip2: I/O or other error, bailing out.  Possible reason follows.
  bzip2: Broken pipe
          Input file = mylog.bz2, output file = (stdout)
  </code></pre>
  
  <p>It looks like <code>head</code> command is exiting abruptly and <code>bzip2</code> receives SIGPIPE.
  What can I do with this? I need to be sure that first 10 lines will be in the <code>$output</code> file no matter what. There is no guarantee that this is always the case if one of the processes fails miserably I guess.</p>