title: Is there a way to capture the output of a command, and its return value into variables in a shell script?
body: <p>So, let's say that I have a command, <code>foo</code>, in a script which has both a return value, and an output string that I'm interested in, and I want to store those into a variable (well at least its output for the variable, and its return value could be used for a conditional).</p>
  
  <p>For example:</p>
  
  <pre><code>a=$(`foo`)   # this stores the output of "foo"
  if foo; then # this uses the return value
      stuff...
  fi
  </code></pre>
  
  <p>The best thing that I could think of to capture that output is to use some temporary file:</p>
  
  <pre><code>if foo &gt; $tmpfile; then
      a=$(`cat $tmpfile`)
      stuff...
  fi
  </code></pre>
  
  <p>Is there anyway I could simplify that?</p>