Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.
 $ 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
share|improve this question
2  
use echo $0 to get the current shell –  Manula Waidyanatha Aug 14 '12 at 10:17

3 Answers 3

up vote 8 down vote accepted

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

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
3  
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

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

Your Answer

 
discard

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.