title: bash exec sending output to a pipe, how?
body: <p>I experiment with exec'ing the bash itself only to redirect the output. If I use redirection like</p>
  
  <pre><code>exec &gt;bla.log
  ls
  exec 1&gt;&amp;2
  </code></pre>
  
  <p>it works as expected: the <code>ls</code> output ends up in <code>bla.log</code> and after the second <code>exec</code> things are back to normal, mainly because handle 2 is still bound to the terminal.</p>
  
  <p>Now I thought to send the output through a pipe instead of into a file, a trivial example being <code>exec | cat &gt;bla.log</code>. However, the command immediately returns. To figure out what is going on, I did this:</p>
  
  <pre><code>exec | bash -c 'echo $$; ls -l /proc/$$/fd /proc/23084/fd'
  </code></pre>
  
  <p>where 23084 is the bash currently running and got this:</p>
  
  <pre><code>24002
  /proc/23084/fd:
  total 0
  lrwx------ 1 harald harald 64 Aug 14 20:17 0 -&gt; /dev/pts/1
  lrwx------ 1 harald harald 64 Aug 14 20:17 1 -&gt; /dev/pts/1
  lrwx------ 1 harald harald 64 Aug 14 20:17 2 -&gt; /dev/pts/1
  lrwx------ 1 harald harald 64 Aug 14 20:17 255 -&gt; /dev/pts/1
  
  /proc/24002/fd:
  total 0
  lr-x------ 1 harald harald 64 Aug 14 21:56 0 -&gt; pipe:[58814]
  lrwx------ 1 harald harald 64 Aug 14 21:56 1 -&gt; /dev/pts/1
  lrwx------ 1 harald harald 64 Aug 14 21:56 2 -&gt; /dev/pts/1
  </code></pre>
  
  <p>As we can see, the sub-process 24002 is indeed listening to a pipe. But it certainly is not the parent process, 23084, which has this pipe open. </p>
  
  <p>Any ideas what is going on here?</p>