title: bash pipestatus in backticked command?
body: <p>in bash, if I execute a couple of commands piped together inside of backticks, how can I find out the exit status of the first command?</p>
  
  <p>i.e. in this case, I am trying to get the "1". which I can get via PIPESTATUS[0] if I am not using backticks, but which doesn't seem to work when I want to saving the output:</p>
  
  <pre><code>## PIPESTATUS[0] works to give me the exit status of 'false':
  $ false | true;
  $ echo $? ${PIPESTATUS[0]} ${PIPESTATUS[1]};
  0 1 0
  
  ## doesn't work:
  $ a=`false | true`;
  $ echo $? ${PIPESTATUS[0]} ${PIPESTATUS[1]};
  0 0
  </code></pre>
  
  <p>More generally, I am trying to accomplish: save the last line of the output of some program to a variable, but be able to tell if the program failed:</p>
  
  <pre><code>$ myvar=` ./someprogram | tail -1 `;
  $ if [ "what do i put here" ]; then echo "program failed!"; fi
  </code></pre>
  
  <p>Ideally I'd also like to understand what is going on, not just what the answer is.</p>
  
  <p>Thanks.</p>