How to detect if a script is being sourced
Posted
by brianegge
on Stack Overflow
See other posts from Stack Overflow
or by brianegge
Published on 2010-04-21T13:28:23Z
Indexed on
2010/04/21
15:23 UTC
Read the original article
Hit count: 347
I have a script where I do not want it to call 'exit' if it's being sourced. Initially I though checking if $0 == bash
but this has problems if the script is sourced from another script, or if the user sources it from ksh. Is there a reliable way of detecting if a script is being sourced?
© Stack Overflow or respective owner