Wed. Nov 29th, 2023

Key Takeaways

  • Trying out different Linux shells, like Zsh, can be a beneficial and easy process to find the one that aligns with your preferences.
  • Each shell has its own unique features and way of performing tasks, and different shells can greatly impact your workflow.
  • The chsh command allows you to change your default shell.

Bash isn’t the only Linux shell. It’s easy to try out other shells, like Zsh, which is very popular. When you’ve found one you like, use the chsh command to make it your default shell. We’ll show you how.

Why a Shell Is Important

The shell sits between you and the operating system. It provides the environment inside a terminal window that allows you to type commands and run programs. The shell checks your input and figures out what you want. If it can perform your bidding itself, it does so. If it needs outside help, it searches the path and finds the programs that can do whatever it is you requested.

There are many different shells available on Linux. They all allow you to perform the same core tasks: explore the file system, work with files, launch programs, and run scripts. However, they each perform these tasks in their own way, and have their own special features and idiosyncrasies.

Shells tend to be designed by people who want things to behave in a specific way. If your thinking aligns with that designer’s, that shell might well be a good fit for you. Plus, trying a new shell on Linux is easy.

In most Linux distributions, including Ubuntu, the default shell is bash. It does a great job and is very capable. However, another shell might offer a time-saving difference that would have a big impact on your workflow. You’ll never know if you don’t look!

What Are The Best Linux Shells?

We’ve covered the different Linux shells before, but here’s a quick introduction to the most common:

  • bash: The Bourne again shell is the default in many distributions.
  • rbash: This Restricted bash shell provides minimal functionality to the person or script running in it.
  • ash: The Almquist shell is a lighter version of bash.
  • dash: The Debian Alquist Shell is the default shell script in Ubuntu. While bash is the default login and interactive shell, dash is used to run system processes because it’s much lighter than bash.
  • zsh: The Z shell is a modern take on the bash family of shells. It offers neat improvements, like command spellchecks and suggested corrections.
  • fish: This friendly interactive shell was written from scratch and isn’t derived from any of the other shell families. It’s intended to be user-friendly. Amongst its many other perks, fish offers suggestions for commands based on your history and the contents of the current folder, similar to predictive text.
  • ksh: The KornShell provides a particularly strong scripting language.

List the Installed Shells

To see which shells are installed on your computer, use this command. It simply lists the contents of the /etc/shells file:

cat /etc/shells

cat /etc/shells in a terminal window

We’ve mentioned bash, dash, and rbash, but what is sh?

sh is the Thompson shell, written way back in 1971 by Ken Thompson of Bell Labs fame. It’s no longer maintained and has long since been superseded by modern shells. It’s included purely to maintain compatibility with older scripts that still have the following as their first line:


This instructs the system to use the sh shell to execute the script. Do you really have that ancient shell on your machine, and is it being used to run your scripts? The which command will tell us which program actually runs when you type a command.

Let’s see what runs when you type sh:

which sh

This appears to find a binary. if we dig a little deeper, though, we’ll see that it’s a symbolic link that actually points to dash, the lightweight shell used to execute scripts:

ls -l /bin/sh

which sh in a terminal window

That’s a neat, lightweight way to provide a safety net for scripts that expect to find sh on modern systems.

Installing Another Shell

Let’s install the fish shell and set it as the default for dave. On Ubuntu, we type the following command:

sudo apt-get install fish

sudo apt-get install fish in a terminal window

On Manjaro, use pacman:

sudo pacman -Sy fish

sudo pacman -Sy fish in a terminal window.

On Fedora, type the following:

sudo dnf install fish

sudo dnf install fish in a terminal window

When the installation is complete, you can check the installed shells once more:

cat /etc/shells

cat /etc/shells in a terminal window

Our new shell appears as /usr/bin/fish. Take note of that path—you’ll need it shortly.

The $SHELL Environment Variable

The $SHELL environment variable holds the name of your current shell. We can check which one it’s set to with echo:

echo $SHELL

Let’s start the fish shell:


Now, let’s check again what the $SHELL environment variable says:

echo $SHELL

echo $SHELL in a terminal window

The first time we use echo $SHELL, we’re in the bash shell. The environment variable holds the path to the bash executable, /bin/bash.

When we launch the fish shell, we get a friendly welcome message and the command prompt changes. What might be surprising is the $SHELL environment still holds the path to the bash executable, /bin/bash. That’s okay—this is normal.

When you launch a new shell (or any other program), it inherits the environment of the parent shell. So, the fish shell inherits the global and exported environment variables from the bash shell. Because the value in the $SHELL environment variable hasn’t been changed, it has the same value in the fish shell that it did in the bash shell.

We’re running fish like any other program. We can also use exit to exit the fish shell. It closes like any other program, and we return to the bash shell.

That’s great for trying out new shells, seeing what they can do, and whether you get along with them. You can explore before you make the jump and adopt one as your go-to shell.

If you decide to make the fish—or any other shell—your default, you’ll need to use the chsh command.

The chsh Command

The chsh command allows you to change your default shell. The trick is being aware that it allows you to change both the default login and default interactive shells. You might want to change one or the other, or both.

Whenever you log in to obtain a command prompt, you use the shell configured to be your login shell. When you’re already logged in and open a terminal window, you use the shell configured to be your interactive shell. These can either be the same or different shells.

To set your login shell, use chsh with no parameters:


chsh in a terminal window

You’re prompted for your password. Then, you must type the path to the new shell and hit Enter.

If we make a remote connection to this test computer from another, we’ll find ourselves in the fish shell once we’ve logged in.

SSH connection showing the fish shell as the login shell, in a terminal window

To change your interactive shell use chsh with the -s (shell) option. Pass the path to the new shell on the command line:

chsh -s /usr/bin/fish

chsh -s /usr/bin/fish in a terminal window

You’re prompted for your password and returned to the command prompt of your current shell. You need to log out and back in for the change to take effect. When you do, you’ll see the greeting and the fish shell command prompt.

The $SHELL environment variable now holds the path to your new default shell:

echo $SHELL

echo $SHELL in a terminal window

Changing Another User Account’s Shell

If you have root privileges and can use sudo, you can change the shells of other user accounts. The command is the same as before, with the addition of that person’s username added to the command line:

sudo chsh -s /usr/bin/fish mary

sudo chsh -s /usr/bin/fish mary in a terminal window

When mary next logs in, she’ll see the new shell when she opens a terminal window.

user mary at the fish shell command prompt, in a terminal window

Everybody Has a Favorite

As long as you’re comfortable with your choice of shell, and it works for you, that’s great! Just remember, it must be able to run common scripts, such as installation routines. For the shells mentioned here, this shouldn’t be a problem.

Of course, you can also download and install a new shell, and take it for a test drive without making any configuration changes to your computer. When you’re ready to tie the knot, chsh will perform the ceremony for you.

Source link

By John P.

Leave a Reply

Your email address will not be published. Required fields are marked *