Can we determine inside the very script whether it started as
source (.) or
executable (shebang or something alike)?
$0 if you have a script:
#!/bin/bash echo $0
and make it executable (
chmod 755 test.sh) and
bash (or something else depending on how you are logged in and what your shell is).
If you do
./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-sourced else ..... your code here for sourced fi