Understanding the $SHELL Environment Variable in Unix and Linux
- Chris

- Jun 3
- 1 min read

In Unix and Linux systems, the $SHELL environment variable indicates the parent shell that initiated your current session.
This can be useful for understanding the runtime environment, particularly when troubleshooting or scripting.
It’s important to know that this value doesn’t always reflect your default login shell—it shows the shell that started your current session.
For example, if you start a new shell within your login shell, $SHELL still shows the original one.
Here’s a practical demonstration:
$ whoami
chris
$ echo $SHELL
/bin/bash
$ zsh
echo $SHELL
/bin/bashIn this case, even after switching to zsh, the value of $SHELL remains /bin/bash. This is because it reflects the shell that started the session, not the current interactive shell.
Understanding Default Shells
The system-wide default shell is usually defined in /etc/default/useradd.
Each user’s default shell is listed in /etc/passwd.
To check or change the default shell for a user:
Check:
$ grep chris /etc/passwdChange using chsh:
$ chsh -s /bin/ksh chrisOr using usermod (requires root):
# usermod -s /bin/ksh chrisThese commands allow users or administrators to specify which shell environment they prefer, which is essential for scripting, user experience, and system customization.




Comments