title: How to detect if a script is being sourced
body: <p>I have a script where I do not want it to call <code>exit</code> if it's being sourced.  </p>
  
  <p>I thought of checking if <code>$0 == bash</code> but this has problems if the script is sourced from another script, or if the user sources it from a different shell like <code>ksh</code>.  </p>
  
  <p>Is there a reliable way of detecting if a script is being sourced?</p>