title: How to get the exit code from the source script
body: <p>I have two scripts main script and sub script and I called the subscript using source script, if the specified package is not installed then it should return exit code 1.</p>
  
  <p>If I run the main script by using <code>bash main.sh</code> I am unable to get the subScriptExitCode from the main script</p>
  
  <p><strong>main script</strong></p>
  
  <pre><code>source "sub.sh"
  
  subScriptExitCode=$?
  
  log "subScript ExitCode: $subScriptExitCode"
  
  if [ $subScriptExitCode -ne 0 ]; then
      exit $subScriptExitCode
  fi
  </code></pre>
  
  <p><strong>sub script</strong></p>
  
  <pre><code>type -p &lt;package&gt;
  
  subScriptExitCode=$?
  
  if [ $subScriptExitCode -ne 0 ]; then
      exit 1
  fi
  </code></pre>