In tcsh
, $_
at the beginning of the script will contain the location if the file was sourced and $0
contains it if it was run.
#!/bin/tcshset sourced=($_)if ("$sourced" != "") then echo "sourced $sourced[2]"endifif ("$0" != "tcsh") then echo "run $0"endif
In Bash:
#!/bin/bash[[ $0 != $BASH_SOURCE ]] && echo "Script is being sourced" || echo "Script is being run"