X

Send us a Topic or Tip

Have a suggestion for the blog? Perhaps a topic you'd like us to write about? If so, we'd love to hear from you! Fancy yourself a writer and have a tech tip, handy computer trick, or "how to" to share? Let us know what you'd like to contribute!

Thanks for reaching out!

Moving From Bash to Zsh: Terminal Changes in macOS Catalina

macOS Terminal Icon

macOS Catalina has a number of new features and capabilities, but one change that’s often overlooked is the new shell used in Terminal to interact with the Mac via the command line. 

The quick take away is Apple is moving from the Bash (Bourne Again Shell) to a newer Zsh. In this Rocket Yard guide, we’ll look at how this change to Terminal and the command line affects you.

What is a Shell?

At the simplest level, a shell is a program that allows you to control a computer, in this case, a Mac, using commands you enter with the keyboard. Shells are usually interactive text-based interfaces that accept commands and present the results. There are a number of different shells you can use, but if you’re wondering why anyone would want to use a shell and a command line to control a computer, you need to take a trip back in time to the dawn of the computer age.

In those early days, controlling a computer was a daunting task that could require you to manually load memory locations, one at a time, with the data that would eventually be run as a program. In some cases, this was done by setting a row of switches that represented a memory location address, and then loading data into the memory with another set of switches. This process was labor-intensive and prone to errors.

In many cases, the manually loaded program was for a boot loader that allowed the computer to accept input from a paper tape reader.

Once the paper tape reader was operational, you could load a shell program that allowed a Teletype to be used as a command line interface. Ah, those were the days.

IMSAI 808 personal computer.
Early personal computers like the IMSAI 8080 used an array of switches to load programs manually – Image courtesy of Judson McCranie.

Using a shell and a command line was a lot easier for working with a computer than rows and rows of toggle switches.

OK, so the shell was a big improvement back then, but why is it still used today with modern computers?

The Shell and the Mac

The Mac makes use of a UNIX-like operating system. And like most Unix or Linux based systems, the command line interface is one of the key methods for interacting with the operating system. The Mac (and many UNIX and Linux systems) also features a graphical user interface to make working with the computer even easier. But the command line still exists, and for working with core components of the operating system it can be very versatile, providing more capabilities than what is available in the GUI (Graphical User Interface).

The shell controls how the command line is presented to the user and what features the command line supports. Most shells offer the following to some degree or other:

  • Shell Syntax: How the shell understands what you enter.
  • Shell Commands: The actual commands the shell can execute.
  • Shell Functions: The ability to group commands together.
  • Shell Parameters: How and where the shell stores values.
  • Shell Expansion: How parameters in a command are expanded
  • Redirect: Controls the input and output of commands.
  • Command Execution: What happens when commands are run.
  • Shell Scripts: The ability to run a file containing multiple shell commands.

Why is Apple Changing the Shell?

Apple is changing from the Bash shell to the Zsh (Z Shell). They haven’t said specifically why the change is occurring, but we can make some educated guesses.

Apple has been using the Bash shell since OS X Jaguar but hasn’t updated Bash since version 3.2 was released in 2007. To put that in perspective, the version of Bash used on your Mac was new when the first iPhone was introduced.

Apple is likely using the older version because the licensing for the Bash shell changed from GNU GPL 2 (General Public License) to GNU GPLv3, which includes restrictions that could cause problems for Apple.

Apple muddled along with the older version for quite a few years, but really, it’s time to move on to something more current.

The Zsh included with macOS Catalina is version 5.7.1 and is the most current version at the time of Catalina’s release. It is also uses a less restrictive MIT license that is more to Apple’s liking.

Note: Although Apple is changing to the Zsh in macOS Catalina, when running in Recovery Mode, the Bash shell is still used when you use the Terminal app.

Am I Forced to Change the Shell?

Yes, and no. Apple will set the Zsh as the default for any new user account that is created in macOS Catalina or later. If you upgraded your Mac from an earlier version of the macOS, then those existing user accounts are still using the Bash shell.

You are, however, free to upgrade all accounts to Zsh, or downgrade an account to Bash (or for that matter, to any shell you wish to use).

How Different is Zsh?

Not very; Bash and Zsh have a very high level of compatibility between them. Both are based on the older Bourne shell. It’s likely most Bash commands and scripts you may be using will run just fine under the Zsh.

Zsh within Terminal showing auto-complete function.
Zsh supports auto-complete, type part of a command followed by hitting the tab key twice and a list of matches is displayed you can select from.

The real advantage to the Zsh is the modern features it includes that make working with the shell very easy. This includes auto complete of command entries, and spell checking, a favorite of mine since I often make a typo in a command that Bash would just let go through and then chide me about there being no such command, while Zsh offers to make a correction to my command for me.

For the fumble-fingered like me, that’s reason enough to change to the Zsh.

What About All My Bash Scripts?

They should run fine; if you do come across a script with issues caused by the shell, you can either take the time to upgrade the script, or simply add a Shebang (#!) to force the script to use the Bash shell that is still included with the macOS:

 Add the following at the beginning of your Bash scripts to ensure compatibility:

#!/bin/bash

Bash script with first line Shebang.
Add the Shebang #!/bin/bash as the first line in your Bash scripts to ensure compatibility.

How to Temporarily Change Shells

Zsh has been included with the macOS for quite a while; it just was never the default before. If you would like to temporarily try out the Zsh, do the following:

Launch Terminal, located at /Applications/Utilities.

At the Terminal command prompt, enter:

zsh

Hit enter or return.

The shell being used in the current Terminal session will change to the Zsh and the command prompt will change to a percent sign (%).

You can return to the bash shell by either quitting Terminal, or at the prompt enter:

bash

Hit enter or return.

You can discover more about the Terminal app in the Rocket Yard guide:

Tech 101: Introduction to the Mac’s Terminal App, Part One

Change The Default Shell to Use

No matter which shell Apple sets for you as the default, you can change it with one of two methods:

From the Terminal command line, enter:

chsh -s /bin/zsh

or

chsh -s /bin/bash

Depending on whether you wish to set Zsh or Bash as the default.

Hit enter or return.

After changing the default shell you will need to open a new Terminal window to see the changes take affect.

You can also set the default shell using System Preferences:

  • Launch System Preferences, and select the Users & Groups preference pane.
  • Click on the Lock icon in the bottom left corner, then supply your administrator password when requested.
  • Right-click on the user account in the sidebar whose default shell you wish to change. From the popup menu, select Advanced Options.
  • Locate the item labeled Login shell.
  • Use the dropdown menu to select one of the available shells.

Note: macOS Catalina does not include an entry in the dropdown menu for Bash. Instead, enter /bin/bash directly in the Login shell item.

Click the OK button when ready.

You can also change the default shell for each user from the Users & Groups preference pane.

What About the Warning Message to Change to Zsh?

If you have Bash set as the default and you launch Terminal or open a new Terminal session, you will see the following message:

The default interactive shell is now zsh. To update your account to zsh, please run chsh -s /bin/zsh.

If you intend to keep using Bash you can remove this message by entering the following at the command prompt:

export BASH_SILENCE_DEPRECATION_WARNING=1

Hit enter or return.

Shell Documentation

It’s beyond the scope of this single article to tell you about the various capabilities of each shell. To do so would really require a book, or two. If you would like to discover more about the Bash and Zsh, you can check out the online documentation about each.

Do you use the Terminal app often? And if so, what shell do you prefer to use? Let us know in the comments below.

Tom Nelson
the authorTom Nelson
Be Sociable, Share This Post!

Leave a Reply

Comment

Name

20 Comments

  • I’m surprised I’m the first to comment on this. I found I needed to add export BASH_SILENCE_DEPRECATION_WARNING=1 to my bash profile for it to work. It makes sense that the variable resets with each launch of terminal. I’m sticking with bash solely because I’m an old curmudgeon who doesn’t like to be told what to do probably, and I’m lazy (look how long I’ve put up with this message before looking up how to suppress it) I’ll eventually switch, I’m sure

  • Hi Tom, very interesting and readable article. I just purchased a new MBP and it’s running Catalina. I was a bit surprised to see that notice about the default interactive shell now being zsh.

    I’m no Terminal power user but use it many times a day. Primarily I have used bash’s rsync command to keep my photo back up folders updated. Since zsh is based on the Bourne shell I imagine that rsync with its -avPh and its –delete flags will behave as it did in bash. And that mv -vn will also behave as it had in bash.

    I’ll look in the zsh man pages for rsync and mv to assure no surprises, but I suspect all will be fine. I haven’t worked on any photos in the new MBP yet as none of my old apps will run in Catalina! So I haven’t had to back up my working folders to the back up folders.

    • rsync is not a bash command or a zsh command, it’s just a command. A shell, such as bash or zsh, is an interpreter that reads the text you type to determine which commands you want to run. But the exact same command is executed regardless of which interpreter you use.

  • I rely heavily on bash. I prefer command-line control to GUI for just about everything.

    The change to zsh is the reason I am postponing upgrading from Mojave to Catalina even though Catalina has been out for a long time.

    This article was helpful in suggesting a possible rationale for the unwelcome change. Thanks for the suggestions for how to avoid having to learn a new shell environment. Life is too short to waste time adapting to pointless upgrades.

  • terminal seems to be stuck in a loop whilst updating. I have the message:

    ‘changing shell for **********’ followed by
    ‘Password for **********’ and a key symbol.

    I can’t enter my password and if I attempt to close terminal an alert tells me the running process chsh is running

    • Usually Terminal will not display any type of response as you enter a password. No characters or symbols are shown. As a results it looks like Terminal is not accepting your input.

      Try just entering the password and hitting Return or Enter to see if the process then continues.

      Tom

  • A really important thing to know when moving your configuration files from bash to zsh is that the ‘~’ that you used in paths to mean your home directory should be changed to ‘$HOME’.

    I hope this saves you some time.

    **Leigh

    • In most shells any job (command or script) you run from within the Terminal is connected to the Terminal app. So if you quit Terminal the job or command will also terminate.

      This is likely the reason for the message you received.

      There are various for creating scripts and running commands independent of the Terminal app. You may wish to investigate the zsh documentation for further information.

      Tom

  • This really helped. Thank you so much. I am beginner trying to learn flutter and the first step was to do this zsh thing, was stuck for a solid half an hour.

    again thank you.

  • “Zsh supports auto-complete, type part of a command followed by hitting the tab key twice and a list of matches is displayed you can select from.”

    You have that backwards actually – bash requires two TAB’s, while zsh only requires one TAB.

    PS – You can check which shell you’re in by typing “echo $0” without the quotes – helpful while trying out different shells.

  • “You can return to the bash shell by … at the prompt enter: bash”

    No! Don’t do that!

    When you first type “zsh”, bash is still open in the background. A zsh session is also running. Now if you type “bash” while still in zsh, you are creating a new bash session. You would now have two instances of bash and one of zsh all open at once. And if you repeat, you will have more and more shell sessions.

    The proper way to go back to your bash session after trying zsh is to type “exit”, or else hit Cntl-D.

  • As a complete Luddite when it comes to shells, I thank you for this work.

    I had a glancing acquaintance with DOS in Windows before Windows Vista forced me to join the Mac brigade, but only use Terminal to delete Snapshots.

    So, from one who knows so little, to someone who’s put the work in NOT to emulate me – THANKS !!

  • Too bad Apple didn’t provide us an automated way to convert startup files (.bashrc, .bash_profile, .bash_logout) to Zsh equivalents.