SHELL environment variable still points to zsh after using bash

SHELL is an environment variable that is passed from bash to zsh when you call zsh. SHELL is not one of the Parameters Set By The Shell in zsh, so its value remains intact.

bash$ SHELL=turtle zsh
zsh$ echo $SHELL
turtle 

For indications that you're in a zsh shell, try:

echo $ZSH_NAME
echo $0

The SHELL variable is traditionally set by the login program, "as specified by the password database". (Copied from What sets the $SHELL environment variable?)


Many shells set a version variable on starting.

bash use BASH_VERSION and zsh use ZSH_VERSION.

Setting both variables to a known value will reliably detect which shell was started:

BASH_VERSION=notbash ZSH_VERSION=notzsh sh -c 'echo "$BASH_VERSION $ZSH_VERSION"'

will print notbash 5.3.1 if sh is zsh or 5.0.2(2)-release notzsh if sh is bash.

Sadly ksh segfaults on using KSH_VERSION with a string value.

Tags:

Shell

Bash

Zsh