I am writing a script which might be sourced either by bash
or zsh
. Depending on the shell, my script might do things differently. Currently I have:
if [[ -n $BASH_VERSION ]]
then
# Do the bash-specific stuff
elif [[ -n $ZSH_VERSION ]]
then
# Do the zsh-specific stuff
fi
Question: Is there a different/better way to detect which shell is sourcing my script? I know about the $SHELL
variable, but that is the default shell, not the shell that is sourcing my script.