🎓 A1Learner
🔍
0 of 50 lessons completed

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_VERSION

Zsh version

On zsh, this prints the zsh version.

echo $ZSH_VERSION

Your shell

echo $SHELL prints the path of your shell, such as /bin/bash.

echo $SHELL

Shell name

echo $0 prints the name of the shell you are using.

echo $0

The 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?