Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top
 $ echo $SHELL
 $ /bin/ksh93
 $ echo $SHELL
 $ 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
 $ ssh test@localhost
test@localhost's password:
 $ echo $SHELL
 $ bash
 $ echo $SHELL

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
 $ T=test ; [[ $T = *est ]] && echo ok
dash: [[: not found
share|improve this question
use echo $0 to get the current shell – Manula Waidyanatha Aug 14 '12 at 10:17
up vote 13 down vote accepted

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.

share|improve this answer

SHELL is specified by POSIX. Quoting:

SHELL This variable shall represent a pathname of the user's preferred command language interpreter. [...]

Running a different shell does not necessarily indicate a change in the user's preference.

It is good to learn the types of things that POSIX specifies and where to search for them since most *.nix systems aim for POSIX compliance. Environment variables are one of those things.

share|improve this answer

The SHELL variable stores the parent shell for your session, which sometimes matches with your default login shell. The $SHELL is the parent shell which spawned the current session.

so, if i use bash for my user and do this: chsh -s /bin/zsh user, when I do echo $SHELL, the shell displayed will still be BASH.

see this article.

share|improve this answer
The article you link to is incorrect. That's the other way around, i.e. SHELL stores your default login shell (at the last login time) which sometimes match your parent shell. This variable is never modified by your parent or current shell. The only action they might do is setting it if (unexpectedly) unset. – jlliagre Aug 14 '12 at 12:01

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.