Bash and Zsh are two popular Linux shells. This guide explores their pros and cons to help you determine which is best to use.
What is a Shell?
A shell is the command-line user interface you use to interact with your computer.
It provides the text input and output that allows you to provide instructions to and receive information from your computer system.
The shell also encompasses other utilities, like scripting for task automation and ease-of-use tools like autocomplete to make navigating the filesystem faster.
Bash and Zsh are both Shells. They’re called ‘shells’ because they exist outside of the core of the operating system, the kernel.
What is BASH?
Bash (short for “Bourne Again SHell“) was released in the late 1980s as a replacement for the Bourne Shell, released in the 1970s.
The Bourne shell itself was made to replace the Thompson shell, the first Unix shell that dated back to 1971.
Bash aimed to provide a completely free shell that had compatibility with existing shell scripts. It quickly gained popularity as the default shell on Linux operating systems, and later on the Apple OS X series of operating systems.
Some notable features of Bash:
- Command-line completion (pressing tab to auto-fill file paths rather than typing them out)
- It can do calculations without relying on external software.
- You can redirect the output of commands easily.
- Use regular expressions in commands.
- Run scripts on startup for customizing your environment
What is ZSH?
Zsh (“Z Shell”) is an extended version of the Bourne shell, with many improvements and features from the Bash shell.
Zsh includes support for plugins and themes, and many of the extended features are considered a big improvement over Bash.
Probably the biggest indicator of the growing popularity of Zsh – Apple has made it the default in their MacOS Operating System, a decision that was likely not taken lightly.
Some notable improvements over Bash in Zsh:
- Plugins and themes!
- You can really customize Zsh with overlays, color schemes – tailor your shell to provide the information you need most
- oh my zsh! is a plugin framework for Zsh which works with a huge number of plugins for just about everything
- Improved commands for navigating the filesystem – just type directory names or the first letter of each directory in a long path, and Zsh will autofill them with it’s best guess
- It’ll also just take you to the nearest matching directory if you make a typo when entering a path – it’s quite forgiving
- Support for floating-point numbers!
- The zmv command makes working with large numbers of files easy.
- File specification without having to use external software
- Named directories – set up shortcuts like ~webdir rather than having to manually type out the path to your web directory or set up soft links
ZSH vs. BASH
What About Scripts?
Due to the overwhelming and long-term popularity of Bash, shell scripts are often generally referred to as Bash Scripts.
While scripts written for one shell aren’t guaranteed to run under another – thankfully, Zsh should run most existing Bash scripts without much modification – though you might want to update them to use some of the improved features available in Zsh.
If you are going to continue using your Bash scripts, make sure that you are including the:
…line at the start of your scripts written for Bash – so your system knows to execute them using Bash, even if the shell you use to interact with your computer is set to Zsh as the default.
Which Should I Use?
If you’re working in an environment where you’ll refer to existing scripts or examples written for Bash, stick with Bash. If you’re breaking new ground and want some of the extra features of Zsh and are happy to have to tweak any code you might wish to use in scripts for the new shell, use Zsh.