title: Exit a bash script from a function whose output is captured
body: <p>I want to completely terminate/exit a bash shell script upon error, but using a function <code>error</code> that lets me display a debug output before termination. Now I have the problem that the <code>exit 1</code> statement inside the error function will <strong>not</strong> terminate the shell script if the function's output is captured via backticks or <code>$()</code>.</p>
  
  <p>Here is my sample script:</p>
  
  <pre><code>    #!/bin/bash
  
      function error ()
      {
              echo "An error has occured: $1"
              exit 1
      }
      function do_sth ()
      {
              if [ $1 -eq 0 ]; then
                      error "First param must be greater than 0!"
              else
                      echo "OK!"
              fi
      }
  
      RESULT=`do_sth 0`
  
      echo "This line should never be printed"
  </code></pre>
  
  <p>How can I immediately terminate the script in the <code>error()</code> function?</p>