I'm writing a bash script that needs to run on the current process for it to be useful.
That is, I want to make sure that the script was invoked with
source script.sh or
. ./script.sh and not
For those of you who don't know the difference refer to this: What is the difference between executing a bash script and sourcing a bash script?
I know I can do
chmod u-x script.sh so it can't be executed without sourcing, but users can may recognise it as a script and
chmod it themselves. I would like a more elegant solution if one exists.
Is there a way for the script to recognise that it has not been invoked with
. and exit with an error?