Shell – Why $SHELL doesn’t change when I run new shell

environment-variablesshell

 $ echo $SHELL
/bin/bash
 $ /bin/ksh93
 $ echo $SHELL
/bin/bash
 $ file /bin/ksh93
/bin/ksh93: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), 
dynamically linked (uses shared libs), for GNU/Linux 2.6.8, stripped

 $ getent passwd test111
test111:x:1008:1008:,,,:/tmp:/bin/ksh93
 $ ssh test@localhost
test@localhost's password:
 $ echo $SHELL
/bin/ksh93
 $ bash
 $ echo $SHELL
/bin/ksh93

I expect the $SHELL to change after running another shell. Why doesn't it?

P.S. However the shell does change, only $SHELL variable remains the same:

 $ dash
 $ echo $SHELL
/bin/bash
 $ T=test ; [[ $T = *est ]] && echo ok
dash: [[: not found

Best Answer

You shouldn't expect this variable to change. It is used to store the path to your default shell, i.e. the one stored in the password database, not which shell you're currently running.

Related Question