title: Reading input while also piping a script via stdin
body: <p>I have a simple Bash script:</p>
  
  <pre><code>#!/usr/bin/env bash
  read X
  echo "X=$X"
  </code></pre>
  
  <p>When I execute it with <code>./myscript.sh</code> it works. But when I execute it with <code>cat myscript.sh | bash</code> it actually puts <code>echo "X=$X"</code> into <code>$X</code>.</p>
  
  <p>So this script prints <em>Hello World</em> executed with <code>cat myscript.sh | bash</code>:</p>
  
  <pre><code>#!/usr/bin/env bash
  read X
  hello world
  echo "$X"
  </code></pre>
  
  <ul>
  <li>What's the benefit of executing a script with <code>cat myscript.sh | bash</code>? Why doesn't do it the same things as if I execute it with <code>./myscript.sh</code>?</li>
  <li>How can I avoid Bash to execute line by line but execute all lines after the STDIN reached the end?</li>
  </ul>