If you have ever used the command line on an *nix system (Unix-based or Unix-like), chances are you’ve used the bash shell. bash (an abbreviation for “Bourne-again shell”) is the default shell for many Unix-like operating systems.
Common examples of Unix-like operating systems include GNU/Linux and macOS. Although many other shells exist for the terminal, one of the most popular shells is
zsh, or the “Z shell”.
While bash and zsh are both powerful shells and share many prominent features, they also possess distinctions that users may have different preferences for. This post will give an overview on the features of and comparison of bash vs zsh, how you can set both as your default shell, as well as some configuration suggestions.
A short history of bash and zsh
In 1971, the very first version of the Unix operating system came with the Thompson shell as its default shell. While lacking in scripting capabilities, this first shell established many of the standards for input/output redirection. With the release of Version 7 Unix in 1979, the new OS came distributed with the Bourne shell as its default shell.
Creation of bash
Later in 1989, Brian Fox created the Bash shell for the GNU Project as a viable software alternative for the Bourne shell. Bash introduced significant improvements over its predecessor. Most prominent of these improvements was its capacity as a scripting language.Users of bash could write their own programs for automating tasks.
These “shell” scripts were executable by typing the file name (typically with a .sh extension). For the most part, bash can support the majority of Bourne and C shell’s features in addition to its own unique additions including command-line editing and integer calculations.
Creation of zsh
Shortly after Bash emerged, a student at Princeton University created the Z shell or “zsh.” Hand in hand with this operating shell is a community-based, online platform called Oh My Zsh which features major extensions such as plug-ins and themes for zsh. As of June 2019, macOS Catalina announced that they would be adopting zsh as their default shell in replacement of bash—a major “win” for zsh enthusiasts.
Bash vs zsh: Common features between bash and zsh
For the most part, bash vs zsh share many convenient features that qualify both as highly efficient shells.
One highly useful feature that both share is the
z command, which allows developers to essentially keep track of their directories. With the
z command, you can navigate to a frequently/recently visited directory just by typing z , followed by the directory name. For example, say you have a directory
newProject located at
~/src/2018/projects/newProject. Using this tool, you can simply type
Another practical aspect of both shells is their tab auto-complete functions. Within each shell, you can just type the command, followed by
-, then hit tab. This action will then immediately display all of the available options for that command. You can then just tab through the available options, until you find the one you’re looking for. Both shells offer flexibility and customization to their command-line auto-completion.
Additionally, a helpful utility for a web design company in both shells, for the most part, is the auto-correction. In the Z shell, if you make an innocent typo while writing a file location, for example, spell correction is built-in and will automatically detect the typo. While this is not custom to bash, you can easily make the necessary adjustments to allow auto-correction by using shopt commands
Even in terms of visual appeal and organization, both shells accomplish the task fairly well.
zsh will differentiate the two by adding color highlighting to directories. Additionally, the font-weight will be slightly bolder. This is extremely helpful to see what’s a file and what’s a directory. The exact colors used will depend on your terminal color settings. On the other hand, bash users can also tweak their interface to reflect their visual needs with the
While these are only some of the various tools offered by both shells, they provide a glimpse of how bash and
zsh admittedly resemble each other. However, they both possess some distinctions that can create a preference for one over the other among developers.
Bash vs zsh: Reasons to consider switching between shells
The commands and overall interaction for bash vs zsh are essentially identical. Knowledge and familiarity with one shell can easily be translated into the other without tackling a steep learning curve. However, both shells do have their share of unique features that may prompt developers to declare a clear preference.
zsh has the leverage of a powerful online community called Oh My Zsh. Oh My ZSH is one of the oldest and most popular options for managing
zsh configurations. Offering over 250 plugins and 140 different themes supplied by the community, Oh My ZSH is a great place to start in customizing the z shell that even comes with an auto-update function that keeps your shell updated. This allows users to work in a shell with a more personalized interface, amp up their workspace with a diverse array of tools, and have access to a convenient out-of-the-box support system. For instance, a highly favorable option for the interface is a right-handed side prompt or a side prompt that auto-hides when typing in long file paths or commands. Even this minute level of flexibility turns developers’ heads towards
On the other hand, Bash has an impressive set of programming functions such as looping and conditional constructs, tilde and brace expansions, and the use of aliases. It also has its share of quirks such as powerful invocation tools, being set into a restricted shell mode, having a particular POSIX mode, and more. Because Bash is also an older and established shell, there are boundless online resources for this software as well.
If you are on OS X, chances are you already have
zsh installed on your system. To check, run the following command:
If it is already installed, you should receive an output message that states
/bin/zsh as the file path for the shell. There is an off-chance that it may display another file path, if for some reason you moved the default installation directory. If you receive an output that states
zsh not found, you will need to install it via Homebrew. You can do so by running the following command:
brew install zsh
For CentOS, Redhat, and Fedora Linux distributions, you can install zsh by running
yum install zsh.
sudo apt-get install zsh will install the shell on Debian and Ubuntu distributions. You can start using zsh even if bash is set to as your default shell. To temporarily try it out, you can just run
zsh on the command line. This will temporarily switch the shell for your current session. To get the most out
zsh, it’s also highly recommended to upgrade your terminal instead of using the default.
Terminal is the default on Mac OS X. While it works perfectly fine, options such as iTerm 2 or Hyper offer an enormous amount of customization. I personally use iTerm 2, although Hyper is an excellent choice available cross-platform.
Setting zsh as your default shell
Now that you have
zsh installed, all you have to do to set it as your default shell is run the following command:
chsh -s /bin/zsh
To start using
zsh, just close your terminal window and open a new one — you will now be running
zsh instead of bash.
Returning to bash
If for some reason you’d like to return to
bash as your default shell, first find out where
bash is installed with
The default path output should be
To change back, just use
chsh -s /bin/bash.
bash will also temporarily switch the shell for that session.
.bashrc, zsh uses a dot file to store user configuration settings,
.zshrc. Stored in the home directory (
~/.zshrc). By default there won’t be a configuration file setup, so you’ll need to create one in your home directory (
Similarly, you can add a
.zprofile file to your home directory.
.zprofile is a script that will run upon login. You can add in any commands you’d like to run upon starting up a new instance of the shell. Given the wide spectrum of customization available in zsh, it can be beneficial to use a dedicate configuration manager. Numerous options exist, including Prezto, Oh My ZSH, and Antigen.
Oh My ZSH
To install Oh My ZSH, simply run
curl -L https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh | sh
This will download the executable shell script and install it on your system. The default settings upon installing Oh My ZSH are a great place to start.
By default, it will install the ‘robbyrussell’ theme (its namesake coming from the original developer of the project).
Additionally, it will install a number of useful plugins. At least a few aspects of the terminal’s display will appear immediately different.
Similar to the above, Oh My ZSH also adds a plugin that will display the current branch you are on in a
git project. Appearing after the working directory in the command prompt, you’ll always know which branch you’re on. This way you never have to
git branch to know the current branch. The
git plugin also adds in several other useful features.
In the example below, the project directory is currently on the
tests branch. We can also know that the working tree is clean, with no changes that you haven’t committed yet. In this case, this is indicated by the fact that the display is green. As soon as you make a change, the display turns another color, indicating that there are new changes to commit:
zsh significantly improves the Git workflow with these types of indications right in the command prompt.
Changing your theme
As mentioned above,
zsh comes with hundreds of different themes to choose from.
robbyrussell will be the default theme, although you can easily change this. To find a new theme offered by Oh My ZSH, you can preview each on the Themes page in the project repo. Given the many choices available, chances are you’ll find one available with almost exactly the features you’re looking for.
Once you find one you like, open up your
.zshrc file, in the home directory. Then, you’ll just need to update the line starting with
ZSH_THEME. Put the name of the name you want to use (inside of quotes), then save the file. Opening a new terminal session should now display the new theme.
You can even set
random as your
ZSH_THEME. This will load a new random theme each time you open up a new session in the shell.
Some themes may require additional packages or fonts, such as the popular Powerline fonts. The theme’s installation’s instructions should specify any additional required packages, though.
As we’ve looked at in this zsh vs bash post,
zsh and bash both share a similar and impressive array of features, but also have their own distinct tools as well. If you’re looking for extensibility, greater customization and advanced features not found in bash, the
zsh shell combined with Oh My Zsh framework is an excellent choice. Regardless of what shell you choose, improved fluency on the command line provides countless benefits in efficiency, automation, and better understanding of your computer’s inner workings.
For an introduction to some of the most essential shell commands, check out our post on basic command line usage.
Crystal is a senior at a public high school in Santa Clarita, CA. She has been invested in technology since her sophomore year, when she took her first Web Development course and used Dreamweaver to design her first websites.
Crystal hopes to continue her studies in computing and technology in her post-secondary education.