Both $SHELL and $0 are environment variables that provide information related to the shell in Unix or Unix-like operating systems, but they differ in the following ways.
$SHELL
- This environment variable stores the path to the default shell for the logged-in user.
- Example:
$ echo $SHELL /bin/bash $ sh sh-3.2 $ echo $SHELL /bin/bashIn the above example, irrespective of the shell that you are currently using, $SHELL will give you the default shell path set for the active user.
$0
- This environment variable provides the name of the current shell when used on any interactive shell prompt. Note that if used within a script, it will give you the name of the script being executed.
- Example:
$ echo $0 bash $ zsh % echo $0 zshIn the above example, you get the name of the current shell when $0 is echoed.

This is not an AI-generated article but is demonstrated by a human.
Please support independent contributors like Code2care by donating a coffee.
Buy me a coffee!

Comments & Discussion
Facing issues? Have questions? Post them here! We're happy to help!