cd
and ls
. A shell used in this way is referred to as an “interactive shell.” You can also string shell commands together with flow control and the like to write shell scripts that automate actions. Those can in turn also be integrated into other automation tools like AppleScript and Keyboard Maestro. In such scripts, you call the shell, usually sh
, with a starting line like #!/bin/sh
. When you use a shell like this, it’s called a non-interactive shell.sh
. The Bourne shell dates back to 1976, and while it isn’t generally used interactively, it’s still the basis for most Unix shell scripts because of its ubiquitousness. In 1989, bash emerged from the GNU Project as a newer, more modern version of sh.cd
, where you can simply type a directory name to navigate to it, and built-in spell-check. zsh also supports plug-ins, which enables things like the popular Oh My Zsh, which adds even more features and makes advanced configuration easier. I also recommend perusing the zsh FAQ, which answers various and sundry questions./usr/bi
, and then press Tab to autocomplete. In most shells, if there’s more than one autocomplete option, the shell will list the options, but you have to keep typing out the correct path by hand until there’s only one option left, after which you can press Tab to fill it in. With zsh, you can instead configure it to show your options as a menu that you can navigate and select with arrow keys, or with a bit more configuration, vi keybindings or any keys you want. In the screenshot below, I entered /usr/local/
and hit Tab to see a menu of subfolders.echo $0
— which shows the name of the shell.echo $SHELL
— which shows the path to the shell.~/.zshrc
. He has set up some nice colors and menu autocomplete with vi keybindings. Here’s a video explaining his configuration in detail.# Use vim keys in tab complete menu:
.#!/bin/sh
, you shouldn’t have problems. Catalina still ships with bash, which emulates sh. However, I wouldn’t be surprised if Apple were to remove bash entirely in the future. Apple suggests having zsh emulate sh by adding the --emulate sh
option to zsh, so you can start a script with #!/bin/zsh --emulate sh
. (Note that this won’t work with the version of zsh that ships with Mojave.) I also refer you to Briegel’s Moving to zsh, part 8, which covers scripting with zsh.zsh
at the command line. Type exit
to leave zsh. If you want to set it as your default shell, Apple offers a couple of ways to do so, as well as a way to change what Terminal uses without changing the default for your account./bin/zsh
in the instructions with /bin/bash
.brew install bash
will update the latest version from Homebrew, which will be installed in /usr/local/bin/bash
. Note that you’ll have Apple’s version in /bin/bash
and Homebrew’s version in /usr/local/bin/bash
. If you need a feature from the newer version of bash that Homebrew installs, be sure to start your scripts with #!/usr/local/bin/bash
.xcode-select -r
to reset xcode-select
.Zsh is a shell designed for interactive use, although it is also a powerful scripting language.
/bin/zsh
.“Oh My Zsh is an open source, community-driven framework for managing your zsh configuration. It will not make you a 10x developer…but you might feel like one”
— Robby Russell
~/.zshrc
. To open the config file (.zshrc), run the command:custom/themes
directory. In this scenario, we’ll install powerlevel9k,~/.zshrc
source ~/.zshrc
iTerm2 > Preferences > Profiles > Colors
if you wish to change the background color of the terminal.iTerm2 > Preferences > Profiles > Text > Change Font
.iTerm2 > Preferences > Profile > Colors > Color Presets > Import
.oh-my-zsh > custom > plugins
directory to view the cloned directory. To access this, run the command open ~/.oh-my-zsh
~/.zshrc
shown belowsource ~/.zshrc