title: Return an exit code without closing shell
body: <p>I'd like to return an exit code from a BASH script that is called within another script, but could also be called directly. It roughly looks like this:</p>
  
  <pre><code>#!/bin/bash
  dq2-get $1
  if [ $? -ne 0 ]; then
    echo "ERROR: ..."
    # EXIT HERE
  fi
  # extract, do some stuff
  # ...
  </code></pre>
  
  <p>Now in the line <code>EXIT HERE</code> the script should exit and return exit code 1. The problem is that</p>
  
  <ul>
  <li>I cannot use <code>return</code>, because when I forget to source the script instead of calling it, return will <em>not</em> exit, and the rest of the script will be executed and mess things up. </li>
  <li>I cannot use <code>exit</code>, because this closes the shell.</li>
  <li>I cannot use the nice trick <code>kill -SIGINT $$</code>, because this doesn't allow to return an exit code.</li>
  </ul>
  
  <p>Is there any viable alternative that I have overlooked?</p>