Source Only Bash Script
In some cases, you may need to import the existing environments in bash. Use the following at the top of your script.
1if [ "${BASH_SOURCE[0]}" -ef "$0" ]
2then
3 echo "Hey, you should source this script, not execute it!"
4 exit 1
5fi
See details in https://unix.stackexchange.com/questions/424492/how-to-define-a-shell-script-to-be-sourced-not-run/424498