title: How to check command status while redirect standard error output to a file?
body: <p>I have a bash script having the following command</p>
  
  <pre><code>rm ${thefile}
  </code></pre>
  
  <p>In order to ensure the command is execute successfully, I use <code>$?</code> variable to check on the status, but this variable doesn't show the exact error? To do this, I redirect the standard error output to a log file using following command:</p>
  
  <pre><code>rm ${file} &gt;&gt; ${LOG_FILE} 2&gt;&amp;1
  </code></pre>
  
  <p>With this command I can't use <code>$?</code> variable to check status on the <code>rm</code> command because the command behind the <code>rm</code> command is executed successfully, thus <code>$?</code> variable is kind of useless here.</p>
  
  <p>May I know is there a solution that could combine both features where I'm able to check on the status of <code>rm</code> command and at mean time I'm allow to redirect the output?</p>