Can we determine inside the very script whether it started as source (.) or executable (shebang or something alike)?
Script started as `source` or `executable`?
shell script;executable
Test on $0 if you have a script:#!/bin/bashecho $0and make it executable (chmod 755 test.sh) and do:source test.shyou get bash (or something else depending on how you are logged in and what your shell is).If you do./test.shyou get ./test.sh, so assuming that the script knows how it is saved on the disc you should do:if [ $(basename $0) == test.sh ] then   ..... your code here for non-sourcedelse   ..... your code here for sourcedfi