title: Get the exit code of a Python script in a Bash script
body: <p>I'm new to Bash and want to catch my Python script exit code.</p>
  <p>My <code>script.py</code> looks like:</p>
  <pre class="lang-python prettyprint-override"><code>#! /usr/bin/python
  def foofoo():
      ret = # Do logic
      if ret != 0:
          print repr(ret) + 'number of errors'
          sys.ext(1)
      else:
          print 'NO ERRORS!!!!'
          sys.exit(0)
  
  def main(argv):
      # Do main stuff
      foofoo()
  
  if __main__ == &quot;__main__&quot;:
      main(sys.argv[1:]
  </code></pre>
  <p>My Bash script:</p>
  <pre class="lang-bash prettyprint-override"><code>#!/bin/bash
  python script.py -a a1  -b a2 -c a3
  if [ $?!=0 ];
  then
      echo &quot;exit 1&quot;
  fi
  echo &quot;EXIT 0&quot;
  </code></pre>
  <p>My problem is that I am always getting <code>exit 1</code> printed in my Bash script. How can I get my Python exit code in my Bash script?</p>