Choosing and changing your Linux shell


There are quite a few shells on Linux system and more that can be easily added. This post examines some of the more popular shells, how they differ and the files that contribute to their configuration.

The default shell on most Linux systems is bash. Unless you make an effort, any user accounts added to the system will be assigned bash as their login shell. Bash has been around since 1989 and was meant to replace the Bourne shell (sh). In fact, if you take a look at /bin/sh, you’ll probably find that it’s nothing more than a symbolic link to /bin/bash.

$ ls -l /bin/sh
lrwxrwxrwx. 1 root root 4 Jan 25  2021 /bin/sh -> bash
 

Popular Shells

Some of the best and most popular shells include:

Those with an asterisk had to be installed on my Fedora and Mint systems.

While all of these shells are nice to use, you’ll only come to fully appreciate any of them by using them for a while.

bash

The most well known shell, bash (a/k/a the “Bourne Again SHell”), is powerful and provides many extremely useful commands for turning even the most complicated tasks into scripts. It includes directory manipulation, tab completion, job control, brace and tilde expansion, aliases, command history, dynamically loaded built-ins and more.

zsh

Also derived from the Bourne shell, zsh can also run nearly any bash script. It’s highly customizable, provides features such as tab completion, spelling correction, command history, remote file expansion, aliases and more.

fish

Especially known for its friendly, helpful manner. It can suggest commands based on your command history. It uses colors to highlight syntax issues. For example, start typing a command and letters will turn red if you use a wrong character. It also supports scripting and aliases.

ksh

The Korn shell, ksh, provides command-line editing features, job control, functions and aliases and advanced I/O features.

tcsh

The tcsh shell is an enhanced C shell (csh). Some of its key feature include programmable command completion and command-line editing. It feels simple, but includes a nice collection of essential features. Its lengthy man page details them.

Viewing available shells

To determine what shells are installed on your Linux systems, you can look at the /etc/shells file. However, you’ll likely notice that most are listed more than once (e.g., /bin/bash and /usr/bin/bash). If you run a command like this one, you’ll see that the “extras” are simply hard links, not separate shells:

$ ls -li /bin/bash /usr/bin/bash
312765 -rwxr-xr-x. 1 root root 1390080 Jan 25  2021 /bin/bash
312765 -rwxr-xr-x. 1 root root 1390080 Jan 25  2021 /usr/bin/bash

The 312765‘s at the beginning of these lines display the inode numbers.

A more complicated, but easier way to see the distinct shells is to use a command like this that removes the duplicates, but only shows the shells (not the full paths):

$ cat /etc/shells | awk -F "https://www.networkworld.com/" '{print $NF}' | sort | uniq
bash
csh
dash
fish
ksh
rksh
sh
tcsh
tmux

Changing your shell

If you want to try a different shell, you can use the chsh (change shell) command. You can do this by typing “chsh” and having it prompt you for the new shell or by supplying it with your shell choice like this:

$ chsh -s /bin/zsh

Either way, you’ll be prompted for your password and the required change will be made in the /etc/passwd file. Your current shell will continue to be active until your next login.

If you want to change the default for all new accounts (assuming you’re the only one who sets them up), you might create an alias for the adduser command that makes use of the -s option to specify that shell.

$ alias adduser="adduser -s /bin/zsh"
$ echo 'alias adduser="adduser -s /bin/zsh"' >> ~/.bashrc

The second of the two commands above works only for bash, however, as it stores the alias in your .bashrc file. You need to change this to the configuration file for a different shell when you are not using bash. For example, you would save the alias to the ~/.config/fish/config.fish file if you were using fish.

You can also try out a shell by invoking it on the command line like this:

$ /bin/fish	<== start fish
Welcome to fish, the friendly interactive shell

Shell configuration files

Most shells make use of one or more configuration files that establish many shell settings such as how many commands will be saved in your command history.

bash

When you log in as a bash user, the first file read is /etc/profile (a relatively system-wide configuration file). It sources the /etc/bashrc file (the bash-specific configuration file) when you’re using bash. After that, your local ~/.bashrc file will be run. This means that you can control personal settings by making changes to that file.

zsh

The zsh shell uses the /etc/profile and ~/.zsgrc files.

fish

The fish shell uses only its own config file — ~/.config/fish/config.fish.

ksh

The ksh shell uses the /etc/profile file.

tcsh

The tcsh shell will read a ~/.tcshrc file is you set one up.

Wrap-up

Linux systems offer a lot of choices for what shell you use. Some you’ll love and others you maybe won’t, but it’s easy to try any of them out and change your shell when you find the one you prefer.

Join the Network World communities on Facebook and LinkedIn to comment on topics that are top of mind.

Copyright © 2021 IDG Communications, Inc.



Source link