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.

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

My administrator says that my default shell is set to bash, but

$ echo $SHELL

Is the default shell related to the SHELL variable at all? Is not, what is the variable used for?

share|improve this question
up vote 5 down vote accepted

That's not 100% true. For example:

$> echo $SHELL
$> /bin/ksh
$] echo $SHELL

$SHELL contains the parent shell for your session, which is commonly your login shell as dictated by your user entry in /etc/passwd. More clearly, $SHELL is the parent shell from which your current session spawned. In my example the current shell, Korn, is technically running within BASH, which is why $SHELL was unmodified.

Obviously this is an almost exclusively semantic distinction, however, do not fall into the trap of believing that what you see is always what you get.

share|improve this answer

No, it is not related to default shell.

The system default shell is defined in /etc/default/useradd file.

Your default shell is defined in /etc/passwd file. You can change it by chsh command.

The $SHELL variables usually stores the current shell executable path. Each shell behaves differently on this point. E.g. bash sets the SHELL variable if it is unset when it starts, otherwise it leaves it unchanged. tcsh does not support this variable at all.

share|improve this answer
I did the echo $SHELL from bash. Then, the current shell executable path should have referred to bash, right? – Lazer Nov 17 '10 at 16:56
mumble ... I checked more carefully and edited the response. – andcoz Nov 17 '10 at 18:01

The variable is for your information ("Hey, what shell am I running under?") rather than the way you set the shell. Since Unix environment variables can only propagate down to child processes and not back up to parents, generally environment variables like this are descriptive rather than configuration options.

To see your default shell, look at your entry in /etc/passwd, and to change that, run chsh. (This is assuming you're not using NIS or LDAP for this information; in that case it's unlikely to work in most real-world setups.) And as andcoz notes, the initial defaults for new users added with the standard useradd program are in /etc/default/useradd.

share|improve this answer

The “default shell“ for a unix system administrator is what is stored in the “shell” column of the user database. This is the program that is invoked when you log in in text mode (on a text mode console, or over the network via e.g. ssh).

The ”default shell” for a unix application is either sh or $SHELL. There is some variation as to whether $SHELL is intended to be an interactive shell or a shell to run scripts. The POSIX specification is ambiguous in that regard, reflecting diverging practice:

This variable shall represent a pathname of the user's preferred command language interpreter. If this interpreter does not conform to the Shell Command Language in the Shell and Utilities volume of IEEE Std 1003.1-2001, Chapter 2, Shell Command Language, utilities may behave differently from those described in IEEE Std 1003.1-2001.

That bit about the preferred command language means that some applications may try to run commands in $SHELL, using POSIX shell command syntax. However, the normal way to run a shell command in a unix application is through functions such as system, which is supposed to find a suitable shell regardless of the value of the $SHELL environment variable. Bash and ksh are examples of POSIX-compliant shells. Zsh comes close. Csh is different, and you may occasionally run into trouble due to SHELL being set to csh (it's not very common as most applications do call sh and csh is compatible enough for basic use).

In practice, for a unix user, $SHELL is your preferred interactive shell, i.e., what you want to see when you start a terminal emulator. It doesn't have to be the same as your login shell¹: you can set it in your .profile or .login.

¹ For example, I typically leave whatever login shell is the default, maintain a Bourne-compatible .profile, but set SHELL to zsh if it's available.

share|improve this answer

I always understood environmental variables to be advisory to programs you are running. $SHELL would be the shell you want a program to start when it needs to run a shell. Compare with $EDITOR, you email program might use it to decide which editor to offer you. B/c these environmental variables are so easy to change you can't really rely on them as the final word on what the world is really like.

Related to your question on default shell: chsh is a command that allows you to change your login shell. Before changing it shows you what your current choice is.

share|improve this answer

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.