If you are comfortable with what a terminal, shell, and Bash are, this guide covers the practical side: how to find out which shells are available on your computer, how to change and configure your default shell, and how to run shell scripts. If you are new to these concepts, start with Terminal, Shell, Bash: What’s the Difference? first.
Why use a command-line shell on modern operating systems?
Physical computer terminals were superseded by personal computers with graphical interfaces decades ago, but command-line interfaces and shell scripts remain essential tools for developers. They offer automation, precision, and control that graphical interfaces simply cannot match. Modern operating systems make these capabilities available through terminal emulators, software that replicates the behaviour of a physical terminal within a standard desktop window.
On macOS, the built-in option is the aptly named Terminal, though many developers prefer third-party alternatives such as iTerm2 or Warp. On Windows, the modern option is Windows Terminal. Whichever emulator you choose, you can configure it to load whichever shell you prefer as the default.
What shells are available on my computer?
Bash and zsh are two of the most common shells but there are many more available. On a Mac or Linux machine you can list all installed shells by running:
cat /etc/shells
This will return something like:
/bin/bash
/bin/csh
/bin/dash
/bin/ksh
/bin/sh
/bin/tcsh
/bin/zsh
Changing your default shell
To change your default shell on macOS or Linux, enter the chsh command and provide one of the paths listed in /etc/shells. For example, to switch to Bash:
chsh -s /bin/bash
Configuring your shell
When configuring your preferred shell you can add preferences, environment variables, and aliases to the following configuration files:
- zsh –
~/.zshrcor~/.zprofile - bash –
~/.bashrcor~/.bash_profile
If you would like help getting started with shell configuration, Oh My Zsh is a popular framework for managing zsh configuration, and Oh My Bash provides the equivalent for Bash users.
Adding other shells to your computer
You can install shells beyond those shipped with your OS. For example, to install Fish (a shell known for its user-friendly features and helpful defaults), follow the instructions at fishshell.com. Once installed, its path (e.g. /bin/fish) will be added to /etc/shells, making it available as a default shell or for running Fish scripts.
Running shell scripts
Bash vs Zsh compatibility
This is an area that causes a lot of confusion, often compounded by forum answers that are not quite accurate.
Both Bash and zsh are backwards compatible with Bourne, meaning a script written for the original Bourne shell will run on either. However, Bash and zsh each have their own additional commands and features that are not mutually compatible. A script that uses Bash-specific syntax will not necessarily run correctly in zsh, and vice versa.
The solution is the shebang line at the top of a script. This tells the operating system which shell interpreter to use for that particular script, regardless of what your default shell is:
#!/bin/bash
When you run a script containing this line, the OS checks /etc/shells to confirm that Bash is available and then uses it to execute the script, even if your terminal’s default shell is zsh. The shell you use interactively in your terminal and the shell used to run a given script are entirely independent.
If no shebang line is present, the script will be run by your default shell, which may or may not produce the expected results.
Shell in web development
When tutorials and documentation for web development tools refer to “the shell”, they almost always mean a Unix-style command-line shell, and in many cases they are specifically thinking of Bash. If you are on macOS or Linux you will be well served by whichever shell is your default. Windows developers can access a compatible environment via Windows Subsystem for Linux (WSL), which installs a full Linux shell environment directly on Windows.
You will also quickly encounter command-line text editors when working in the shell, most commonly nano and vim. Nano is the more beginner-friendly of the two, with simple on-screen prompts. Vim is considerably more powerful but has a steep learning curve. Knowing that these are text editors that run inside the terminal, rather than separate applications, will save you some confusion when you first encounter them.