Linux Shells and Types Explained

Linux shell is a command language interpreter. It provides a way to execute commands, create script files, run programs, work with the Linux file system, compile computer code, and manage the computer. Simply put, it is a command-line interface that allows us to interact with the host Linux system via commands.

The shell provides a command prompt for typing a command. After hitting the Enter key, the shell interprets whatever text we type at the command prompt. If the typed text is a valid command, the shell executes that command and displays the output. If not, it shows the Command not found error message.

Shell derivation

The first shell was developed at Bell Labs by S. R. Bourne for early versions of UNIX. It is known as the Bourne Shell or sh. Since it was the first shell and was used as the default shell for a long time, many UNIX features and functions were developed around it. All UNIX systems need this shell to function correctly.

Linux is derived from UNIX. Many UNIX features that use the sh shell as the default shell are part of Linux. They require the sh shell to function. However, Linux does not use the sh shell as the default shell. It uses the bash shell as the default. It links all features and functions that require the sh shell to its default shell. However, this does not mean you cannot use the sh shell on Linux. Linux includes the sh shell but not as the default shell. It includes it as an additional shell. To use it, you need to change the default shell.

The bash shell is the updated and improved version of the sh shell. You can run all the features and functions that require the sh shell with the bash shell. Unless you are habitual of using the sh shell or have any specific reason, switching to the sh shell on Linux is unnecessary.

Shell availability

Apart from the default shell, Linux and Unix include many other shells. Each shell has its distinct properties and default environment variables. Each shell contains a collection of built-in commands and additional tools that allow us to interact with the host system.

Usually, a Linux distributor picks a shell that meets its requirements, customizes it for its audiences, and sets it as the default shell on its distribution. No matter which shell a distributor chooses, they all are derived from the original Bourne Shell. Since all shells are derived from the same Bourne Shell, they share several features and functions. These similar features and functions make learning different shells easier. Once you learn one shell, you can quickly learn and use others.

Popular Linux shells

The most popular Linux and UNIX shells are the following.

The ksh (Korn Sh) shell

This shell was designed and developed by David G. Korn. This shell is popular among UNIX System V users. It provides built-in arithmetic, string manipulation, and arrays.

The bash (Bourne-Again Sh) shell

This shell is the improved version of the original Bourne Shell. It is the default shell on many popular Linux distributions, such as Red Hat, Ubuntu, and Debian. It is highly customizable. Distributors customize it for general purposes and all kinds of users.

The csh shell

William Joy developed this shell. This shell is popular among BSD UNIX users. This shell is mainly customized for the programmers. It provides an environment for the C programming language. Command-line editing, job control, spelling correction, arrays and syntax, and filename completion are common features of this shell. The tcsh shell is an improved version of the csh.

The dash shell

This shell is a bare-bones and POSIX-compliant implementation of the sh shell. It is used only at system boot time. It is faster than the bash shell. In earlier versions of Ubuntu, it was the default shell.

Shell types

You can classify shells into two types: shells optimized for all users and shells optimized for programmers. Shells such as sh shell, bash shell, k shell, and dash shell are designed for general purposes and all users. Shells such as csh shell and tcsh shell are designed for programmers.

Which shell should I use?

If you are a typical Linux user or a system administrator, you should choose a shell optimized for general purposes, such as the bash shell. Or, if you are a programmer and use Linux mainly for programming purposes, consider choosing a shell optimized for programming-related tasks, such as the tcsh shell.

Viewing the default shell

To view the current shell, use the echo $0 command.

$echo $0

Listing all available shells

To list all available shells, use the cat /etc/shells command or the chsh –l command. Both commands list all available shells on the system.

$cat /etc/shells
$chsh -l

viewing the default shell and listing all available shells

Changing the current shell temporarily

To change the current shell temporarily, use the following command.

$exec [path of the new shell]

For example, the following command sets the current shell to the csh shell.

$exec /bin/csh

This command changes the current shell only in the current session. When the user terminates the current session, his shell changes to the default shell again. Let's understand it through an example.

  • View the current shell and change it to the csh shell.
  • Verify the current shell is changed to the csh shell.
  • Terminate the current session and start a new session.
  • In the new session, view the current shell again.
  • If the current shell is set to the default shell again, it verifies that the last change was temporary.

changing shell temporarily

Changing the default shell permanently

To change the default shell permanently, use the following command.

$chsh -s [path of the new shell]

For example, to permanently set the default shell to the csh shell, use the following command.

$chsh -s /bin/csh

This command changes the default shell in the configuration file that sets the user profile when the user login. Since Linux reads the user's configuration file at the time of user login, this change only occurs when the user login the next time. Let's understand this through an example.

  • View the current shell and set it to the csh shell permanently.
  • Recheck the current shell before terminating the current session. The current shell must not change yet.
  • Terminate the current session, log in again, and check the shell.
  • If you get the csh shell, it verifies that the default shell has been changed to the csh shell.

changing shell permanently

Conclusion

Linux includes many shells. Each shell offers different features and functions. In this tutorial, we discussed the most popular shells and learned to list all available shells and change the default shell to the desired one.

ComputerNetworkingNotes Linux Tutorials Linux Shells and Types Explained

We do not accept any kind of Guest Post. Except Guest post submission, for any other query (such as adverting opportunity, product advertisement, feedback, suggestion, error reporting and technical issue) or simply just say to hello mail us ComputerNetworkingNotes@gmail.com