title: Need explanations for Linux bash builtin exec command behavior
body: <p>From <a href="http://www.gnu.org/software/bash/manual/bashref.html#index-exec-113" rel="noreferrer">Bash Reference Manual</a> I get the following about <code>exec</code> bash builtin command:</p>
  
  <blockquote>
    <p>If command is supplied, it replaces the shell without creating a new process.</p>
  </blockquote>
  
  <p>Now I have the following <code>bash</code> script:</p>
  
  <pre><code>#!/bin/bash
  exec ls;
  echo 123;
  exit 0
  </code></pre>
  
  <p>This executed, I got this:</p>
  
  <pre><code>cleanup.sh  ex1.bash  file.bash  file.bash~  output.log
  (files from the current directory)
  </code></pre>
  
  <p>Now, if I have this script:</p>
  
  <pre><code>#!/bin/bash
  exec ls | cat
  echo 123
  exit 0
  </code></pre>
  
  <p>I get the following output:</p>
  
  <pre><code>cleanup.sh
  ex1.bash
  file.bash
  file.bash~
  output.log
  123
  </code></pre>
  
  <p>My question is:</p>
  
  <p>If when <code>exec</code> is invoked <em>it replaces the shell without creating a new process</em>, why when put <code>| cat</code>, the <code>echo 123</code> is printed, but without it, it isn't. So, I would be happy if someone can explain what's the logic of this behavior.</p>
  
  <p>Thanks.</p>
  
  <p>EDIT:
  After @torek response, I get an even harder to explain behavior:</p>
  
  <p>1.<code>exec ls&gt;out</code> command creates the <code>out</code> file and put in it the <code>ls</code>'s command result; </p>
  
  <p>2.<code>exec ls&gt;out1 ls&gt;out2</code> creates only the files, but do not put inside any result. If the command works as suggested, I think the command number 2 should have the same result as command number 1 (even more, I think it should not have had created the <code>out2</code> file).</p>