Jun 04, 2019 macOS 10.15 Switches From bash to zsh. Apple (Hacker News). Starting with the macOS Catalina beta, your Mac uses zsh as the default login shell and interactive shell. Z shell (Zsh) is a Unix shell built on top of bash (the default shell for macOS) with a large number of improvements.
This plugin provides a few utilities to make it more enjoyable on OSX.
To start using it, add the osx
plugin to your plugins array in ~/.zshrc
:
Original author: Sorin Ionescu
This application makes use of the following third party scripts:
Copyright (c) 2012–2019 Harish Narayanan.
Permission is hereby granted, free of charge, to any person obtaininga copy of this software and associated documentation files (the'Software'), to deal in the Software without restriction, includingwithout limitation the rights to use, copy, modify, merge, publish,distribute, sublicense, and/or sell copies of the Software, and topermit persons to whom the Software is furnished to do so, subject tothe following conditions:
The above copyright notice and this permission notice shall beincluded in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OFMERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE ANDNONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BELIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTIONOF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTIONWITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Command | Description |
---|---|
tab | Open the current directory in a new tab |
split_tab | Split the current terminal tab horizontally |
vsplit_tab | Split the current terminal tab vertically |
ofd | Open the current directory in a Finder window |
pfd | Return the path of the frontmost Finder window |
pfs | Return the current Finder selection |
cdf | cd to the current Finder directory |
pushdf | pushd to the current Finder directory |
quick-look | Quick-Look a specified file |
man-preview | Open a specified man page in Preview app |
showfiles | Show hidden files |
hidefiles | Hide the hidden files |
itunes | DEPRECATED. Use music from macOS Catalina on |
music | Control Apple Music. Use music -h for usage details |
spotify | Control Spotify and search by artist, album, track… |
rmdsstore | Remove .DS_Store files recursively in a directory |
Apple has announced that in macOS 10.15 Catalina the default shell will be zsh
.
In this series, I will document my experiences moving bash
settings, configurations, and scripts over to zsh
.
zsh
Promptzsh
zsh
(I believe it is pronounced zee-shell, though zish is fun to say) will succeed bash
as the default shell. bash
has been the default shell since Mac OS X 10.3 Panther.
This series has grown into a book: reworked and expanded with more detail and topics. Like my other books, I plan to update and add to it after release as well, keeping it relevant and useful. You can order it on the Apple Books Store now.
The bash
binary bundled with macOS has been stuck on version 3.2 for a long time now. bash
v4 was released in 2009 and bash
v5 in January 2019. The reason Apple has not switched to these newer versions is that they are licensed with GPL v3. bash
v3 is still GPL v2.
zsh
, on the other hand, has an ‘MIT-like’ license, which makes it much more palatable for Apple to include in the system by default. zsh
has been available as on macOS for a long time. The zsh
version on macOS 10.14 Mojave is fairly new (5.3). macOS 10.15 Catalina has the current zsh
5.7.1.
No.
macOS Catalina still has the same /bin/bash
(version 3.2.57) as Mojave and earlier macOS versions. This change is only for new accounts created on macOS Catalina. When you upgrade to Catalina, a user’s default shell will remain what it was before.
Many scripts in macOS, management systems, and Apple and third party installers rely on /bin/bash
. If Apple just yanked this binary in macOS 10.15 Catalina or even 10.16. Many installers and other solutions would break and simply cease to function.
Users that have /bin/bash
as their default shell on Catalina will see a prompt at the start of each Terminal session stating that zsh
is now the recommended default shell. If you want to continue using /bin/bash
, you can supress this message by setting an environment variable in your .bash_profile
or .bashrc
.
You can also download and install a newer version of bash yourself. Keep in mind that custom bash installations reside in a different directory, usually /usr/local/bin/bash
.
Apple is strongly messaging that you should switch shells. This is different from the last switch in Mac OS X 10.3 Panther, when Apple switched the default to bash
, but didn’t really care if you remained on tcsh
. In fact, tcsh
is still present on macOS.
Apple’s messaging should tell us, that the days of /bin/bash
are numbered. Probably not very soon, but eventually keeping a more than ten year old version of bash
on the system will turn into a liability. The built-in bash had to be patched in 2014 to mitigate the ‘Shellshock’ vulnerability. At some point Apple will consider the cost of continued maintenance too high.
Another clue is that a new shell appeared on macOS Catalina (and is mentioned in the support article). The ‘Debian Almquist Shell’ dash
has been added to the lineup of shells. dash
is designed to be a minimal implementation of the Posix standard shell sh
. So far, in macOS (including Catalina),sh
invokes bash
in sh
-compatibility mode.
As Apple’s support article mentions, Catalina also adds a new mechanism for users and admins to change which shell handles sh
invocations. MacAdmins or users can change the symbolic link stored in /var/select/sh
to point to a shell other than /bin/bash
. This changes which shell interprets scripts the #!/bin/sh
shebang or scripts invoked with sh -c
. Changing the interpreter for sh
should not, but may change the behavior of several crucial scripts in the system, management tools, and in installers, but may be very useful for testing purposes.
All of these changes are indicators that Apple is preparing to remove /bin/bash
at some, yet indeterminate, time in the future.
No, zsh
is available Mojave and on older macOS versions. You can start testing zsh
or even switch your default shell already.
If you want to just see how zsh
works, you can just open Terminal and type zsh
:
The main change you will see is that the prompt looks different. zsh
uses the %
character as the default prompt. (You can change that, of course.) Most navigation keystrokes and other behaviors will remain the same as in bash
.
If you want to already switch your default shell to zsh
you can use the chsh
command:
This will prompt for your password. This command will not change the current shell, but all new ones, so close the current Terminal windows and tabs and open a new one.
Like bash
(‘Bourne again shell’ ), zsh
derives from the ‘Bourne’ family of shells. Because of this common ancestry, it behaves very similar in day-to-day use. The most obvious change will be the different prompt.
The main difference between bash
and zsh
is configuration. Since zsh
ignores the bash
configuration files (.bash_profile
or .bashrc
) you cannot simply copy customized bash settings over to zsh
. zsh
has much more options and points to change zsh
configuration and behavior. There is an entire eco-system of configuration tools and themes called oh-my-zsh
which is very popular.
zsh
also offers better configuration for auto-completion which is far easier than in bash
.
I am planning a separate post, describing how to transfer (and translate) your configurations from bash
to zsh
.
Since zsh
has been present on macOS for a long time, you could start moving your scripts from bash
to zsh
right away and not lose backwards compatibility. Just remember to set the shebang in your scripts to #!/bin/zsh
.
You will gain some features where zsh
is superior to bash
v3, such as arrays and associative arrays (dictionaries).
There is one exception where I would now recommend to use /bin/sh
for your scripts: the Recovery system does not contain the /bin/zsh
shell, even on the Catalina beta. This could still change during the beta phase, or even later, but then you still have to consider older macOS installations where zsh
is definitely not present in Recovery.
When you plan to use your scripts or pkgs with installation scripts in a Recovery (or NetInstall, or bootable USB drive) context, such as Twocanoes MDS, installr or bootstrappr, then you cannot rely on /bin/zsh
.
Since we now know that bash
is eventually going away, the only common choice left is /bin/sh
.
When you build an installer package, it can be difficult to anticipate all the contexts in which it might be deployed. So, for installation pre- and postinstall scripts, I would recommend using /bin/sh
as the shebang from now on.
I used to recommend using /bin/bash
for everything MacAdmin related. /bin/sh
is definitely a step down in functionality, but it seems like the safest choice for continued support.
Overall, while the messaging from Apple is very interesting, the change itself is less dramatic than the headlines. Apple is not ‘replacing’ bash
with zsh
, at least not yet. Overall, we will have to re-think and re-learn a few things, but there is also much to be gained by finally switching from a ten-year-old shell to a new modern one!
This git repo has been shared by many on MacAdmins Slack: rothgar/mastering-zsh, I will certainly dive into that and share about my experiences here!
In the next part we will look at the configuration files for zsh
.