title: Reading Optional Standard Input Without Blocking
body: <p>So I have a function which can optionally be provided with extra data via standard input, which I'm grabbing with <code>cat</code>, however, when there is no standard input <code>cat</code> will block execution.</p>
  
  <p>Here's a silly example:</p>
  
  <pre><code>foo() { echo "$@" "$(cat)"; }
  </code></pre>
  
  <p>Basically it echoes everything given as input via both arguments and standard input.</p>
  
  <p>Is there a way to prevent <code>cat</code> from blocking in this case? Currently I'm having to work around this by only calling <code>cat</code> if an option to do-so is set, but it seems like really all I should need is for <code>cat</code> to return nothing if there's nothing to read.</p>