My bash script uses a lot of checks like:
if [ something bad ] ; then
echo "error message"
exit 1
fi
I have found out that if the user executes it via source my-script.sh
rather than ./my-script.sh
, this exit 1
closes the user's shell !
And the user sees no error message !
How do I know that the script is sourced, and how do I exit (with non-zero status code) the sourced script? In general, what can I do about this?