title: Bash read command doesn't work outside loop
body: <p>I must be missing something very fundamental about the Bash read command. At the shell prompt, this fails to assign the three input fields to the corresponding variables:</p>
  
  <pre><code>% echo a b c | read x1 x2 x3
  % echo $x1 $x2 $x3
  
  % 
  </code></pre>
  
  <p>This works though:</p>
  
  <pre><code>% echo a b c | while read x1 x2 x3 ; do
  &gt; echo $x1 $x2 $x3
  &gt; done
  a b c
  %
  </code></pre>
  
  <p>I only have to read one line of input. Using a while loop is incorrect here, as I lose the values of x1, x2, and x3 when the loop's subprocess exits. I'd have to place all the code that accesses them within the loop body (and perhaps break at the end, for "clarity"), which seems very hackish. Using it within an if command works as well, but suffers from the same subprocess issues as a while loop:</p>
  
  <pre><code>% echo a b c | if read x1 x2 x3 ; then echo $x1 $x2 $x3; fi
  a b c
  % echo $x1
  </code></pre>
  
  <p>BASH_VERSION reports as "4.2.45(1)-release".</p>