Bash, Zsh and Sh
Bash, zsh, and sh are three shells. They all run commands, but they differ in small ways.
Bash version
On bash, this prints the bash version.
echo $BASH_VERSIONZsh version
On zsh, this prints the zsh version.
echo $ZSH_VERSIONYour shell
echo $SHELL prints the path of your shell, such as /bin/bash.
echo $SHELLShell name
echo $0 prints the name of the shell you are using.
echo $0The sh shell
sh is the classic shell. This line runs sh, and sh prints its own name.
sh -c 'echo $0'Example
echo $BASH_VERSION
sh -c 'echo $0'Key points
- Bash: the shell on most Linux systems.
- Zsh: the shell on macOS, with a few extra features.
- Sh: the classic shell, and the oldest of the three.
- Use echo $SHELL to print the path of your shell.
- Use echo $0 to print the name of the shell you are using.
In this example, echo prints the bash version first. The second line runs sh, and sh prints its own name.
Try it Yourself
Edit the code, then press Run.
Running is simulated
Exercise
Which command prints the path of your shell?