title: In bash, what's the best way to exit with the status of a previous command after cleaning up
body: <p>I have a very simple script that does something like the following</p>
  
  <pre><code>#!/bin/bash$
  /some/path/buildAll.sh \
  &amp;&amp; filepath=/tmp/`cat /some/path/conf/version`.tar.gz \
  &amp;&amp; (cd /some/path &amp;&amp; tar czf $filepath .) \
  &amp;&amp; push_file_to_web $filepath
  </code></pre>
  
  <p>I want to clean up the tarball with <code>rm $filepath</code> regardless of whether the above succeeded and exit with the status of the whole command. In other words, the script should exit with status 0 exactly when every step including the cleanup succeeded. What's the cleanest way to do this?</p>