title: Redirect standard input dynamically in a bash script
body: <p>I was trying to do this to decide whether to redirect stdin to a file or not:</p>
  
  <pre><code>[ ...some condition here... ] &amp;&amp; input=$fileName || input="&amp;0"
  ./myScript &lt; $input
  </code></pre>
  
  <p>But that doesn't work because when the variable $input is "&amp;0", bash interprets it as a filename.</p>
  
  <p>However, I could just do:</p>
  
  <pre><code>if [ ...condition... ];then
      ./myScript &lt;$fileName
  else
      ./myScript
  </code></pre>
  
  <p>The problem is that ./myScript is actually a long command line that I don't want to duplicate, nor do I want to create a function for it because it's not that long either (it's not worth it).</p>
  
  <p>Then it occurred to me to do this:</p>
  
  <pre><code>[ ...condition... ] &amp;&amp; input=$fileName || input=  #empty
  cat $input | ./myScript
  </code></pre>
  
  <p>But that requires to run one more command and a pipe (i.e. a subshell).<br>
  Is there another way that's simpler and more efficient?</p>