title: bash: redirect (and append) stdout and stderr to file and terminal and get proper exit status
body: <p>To redirect (and append) stdout and stderr to a file, while also displaying it on the terminal, I do this:</p>
  
  <pre><code>command 2&gt;&amp;1 | tee -a file.txt
  </code></pre>
  
  <p>However, is there another way to do this such that I get an accurate value for the exit status?</p>
  
  <p>That is, if I test <code>$?</code>, I want to see the exit status of <code>command</code>, not the exit status of <code>tee</code>.</p>
  
  <p>I know that I can use <code>${PIPESTATUS[0]}</code> here instead of <code>$?</code>, but I am looking for another solution that would not involve having to check <code>PIPESTATUS</code>.</p>