Created
March 28, 2018 23:06
-
-
Save StudioEtrange/49c437d94c265f811e68b528216819e5 to your computer and use it in GitHub Desktop.
shell detect if sourced
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # https://stackoverflow.com/a/28776166 | |
| sourced=0 | |
| if [ -n "$ZSH_EVAL_CONTEXT" ]; then | |
| case $ZSH_EVAL_CONTEXT in *:file) sourced=1;; esac | |
| elif [ -n "$KSH_VERSION" ]; then | |
| [ "$(cd $(dirname -- $0) && pwd -P)/$(basename -- $0)" != "$(cd $(dirname -- ${.sh.file}) && pwd -P)/$(basename -- ${.sh.file})" ] && sourced=1 | |
| elif [ -n "$BASH_VERSION" ]; then | |
| [ "$0" != "$BASH_SOURCE" ] && sourced=1 | |
| else # All other shells: examine $0 for known shell binary filenames | |
| # Detects `sh` and `dash`; add additional shell filenames as needed. | |
| case ${0##*/} in sh|dash) sourced=1;; esac | |
| fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment