title: Combine output of two concurrent programs with bash
body: <p>I want to capture output from two concurrent programs (tails on logfiles) into one output stream in bash.</p>
  
  <p>I used this example program for testing:</p>
  
  <pre><code>function foo { for i in $(seq 1 10); do echo "program $*"; sleep 1; done }
  </code></pre>
  
  <p>Now the following works fine</p>
  
  <pre><code>(foo bar &amp; foo baz &amp;) | tee /tmp/output
  </code></pre>
  
  <p>but once I add an extra pipe in the mix it no longer works:</p>
  
  <pre><code>(foo bar | grep bar &amp; foo baz &amp;) | tee /tmp/output # does't work
  </code></pre>
  
  <p>The output becomes sequential. I could make a separate program that includes the grep but I'd like to know if there is a way around this.</p>
  
  <p>If someone can explain why it doesn't work I would be very happy.</p>