title: catch exit code in bash script output to screen and log
body: <p>I'm trying to combine 2 lines that work separately, but I can't get them to work together. To capture and exit code of 1:</p>
  
  <pre><code>Python script.py &gt; /logfile.log 2&gt;&amp;1
  ret=$?
  if [ $ret -ne 0 ]; then
       exit $ret
  fi
  </code></pre>
  
  <p>To output the result of the script to the screen and a log file:</p>
  
  <pre><code>Python script.py 2&gt;&amp;1 | tee /logfile.log 
  </code></pre>
  
  <p>I want to combine these 2 commands so that the script will output to the screen and log file, and will also catch the exit code of 1 to abort the script when it fails. I tried combining them in different ways, but the script either continues running, or nothing is output to the screen. Is it possible to do this?</p>