title: Removing created temp files in unexpected bash exit
body: <p>I am creating temporary files from a bash script. I am deleting them at the end of the processing, but since the script is running for quite a long time, if I kill it or simply CTRL-C during the run, the temp files are not deleted.<br>
  Is there a way I can catch those events and clean-up the files before the execution ends?</p>
  
  <p>Also, is there some kind of best practice for the naming and location of those temp files?<br>
  I'm currently not sure between using:</p>
  
  <pre><code>TMP1=`mktemp -p /tmp`
  TMP2=`mktemp -p /tmp`
  ...
  </code></pre>
  
  <p>and</p>
  
  <pre><code>TMP1=/tmp/`basename $0`1.$$
  TMP2=/tmp/`basename $0`2.$$
  ...
  </code></pre>
  
  <p>Or maybe is there some better solutions?</p>