Bash vs Z shell: A Tale of Two Command Line Shells

Harrison Miller
5 min readJun 25, 2019

--

Recently, Apple announced that as of the next version of macOS, Catalina, they will be adopting zsh as their default shell in replacement of bash. As a budding data science student, having learned all my command line on bash, I wondered how this would affect me. Had what I learned in bash just become useless?? Let’s take a look at the two and find out.

A Little Background of Bash and Zsh

The “Bourne-again shell” or bash for short was created in 1989 by Brian Fox. It is a Unix shell and command language written as a replacement for the Bourne shell. It has been distributed widely as the default login shell for most Linux distributions and Apple’s macOS. Bash introduced improvements over Bourne shell including its ability to be used as a scripting language. Users could write their own shell scripts for automating tasks.

“Z shell” or zsh for short, was created in 1990 by Paul Falstad. It is also a Unix shell and command language based on Bourne shell with a large number of improvements, including some features of bash. Zsh also had the ability to be used as a scripting language with the ability to use shell scripts. It currently has very strong community following and support.

Bash vs. zsh:

For the most part bash and zsh are almost identical which is a relief. Navigation is the same between the two. The commands you learned for bash will also work in zsh although they may function differently on output. Zsh seems to be much more customizable than bash. I’ll now run through a few features and how they differ in each.

Auto-completion

One helpful function of both shells is the tab auto-completion functions. In both shells you can type the command followed by pressing tab to display available options after the command. Zsh’s tab-completion is more feature rich giving you a list of options that can be then navigated and selected by the arrow keys rather than having to struggle with case or mess with long list of folders with spaces in it. Zsh even has tab completion for Git!

Auto-correction

If you type fast and loose, in zsh if you make a typo while writing a command, for example, spell correction is built in, will automatically detect the typo, and ask if you want to correct it.

Plug-in support

Zsh has an online community called Oh My Zsh which is one of the oldest and most popular options for managing zsh. It offers over 250 plugins and 140 different themes supplied by the community. This allows users to work in an environment set up specifically to their work flow. Below is a preview of the git plug in.

Bash has a large set of programming functions such as looping and conditional constructs, tilde and brace expansions, and the use of aliases. Bash is also an older and established shell meaning it also has tons of online resources for finding what you need to do. Many of the features of zsh can be replicated in bash through various methods.

Take Zsh for a Spin!

Want to try out zsh before the release of macOS catalina? If you are on macOS you most likely already have zsh on your computer. You can check by running the command: which zsh

If zsh is present on your system it, the path for the installation will be returned. From there to switch to zsh run the command: chsh -s /bin/zsh and you will be prompted for your password.

To start using zsh restart your terminal.

If you want to switch back to bash, run the command: which bash , which will give you the location of your bash installation. Then run: chsh -s /bin/bash

Restart your terminal, and you will be back to familiar territory.

So Which is Better?

All in all, running either shell will get the job done. The current issue with the version of bash on macOS is it is an outdated version 3.2. The current version is 5.0. This is speculated to be mostly due to licensing issues at apple. The switch to an updated shell will be a welcome change.

It seems to be mostly preference when it comes to choosing one over the other. Many of the conveniences provided by zsh can be made to function in bash as well. In my opinion, zsh seems more helpful to me as a newer shell user. Your milage may vary.

For more info on Oh-My-Zsh an excellent community driven framework for managing your zsh configuration, visit here: https://github.com/robbyrussell/oh-my-zsh

--

--