Understanding Different Types of Shells in Linux

Last updated: February 11, 2023 | Linuxopsys

In the Linux realm, there are multiple shells available, each with its own unique features and capabilities to cater to the varying needs and also preferences of the user. For instance, the Bourne shell (sh) offers a minimalist set of features for shell scripting, while the Z shell (zsh) offers some advanced ones such as extended globbing and spelling correction.

Therefore, choosing the shell can be subjective based on the task at hand and the specific requirements. Although it's not necessary to learn all shells, acquiring knowledge on multiple ones can be necessary to improve efficiency (one shell for scripting and the other for interactive use) and to increase functionality (taking advantage of the best feature in each shell).

History

Shells are programs that communicate the user's commands to the operating system, an idea that started in the late 1960s with the early days of computing; Shells have come a long way from their humble beginnings to the cool and feature-rich interpreters that we know today.

There are multiple shells in widespread use like Bash which is the default for most Linux distributions, the Z shell, and Fish shell. These shells can be utilized in two ways, either by typing in commands directly into the Terminal to get results in real time, which is called interactive mode, or by executing a set of commands structured within a text file, which is known as shell scripting.

In most Linux distributions, the default shell is the Bourne again shell (abbreviated to Bash), which is well-suited for most of the tasks you'll encounter. But don't let that limit you! Other shells can also be installed and used simultaneously with the default one, offering you wide flexibility and control over your work.

Types of Shells in Linux

In this next part, we'll be taking a closer look at the different types of shells available in the Linux realm. Starting from the classic Bourne shell (sh) to the newest feature rich Fish shell, we'll discuss each shell's background, usage, key features, and drawbacks.

Whether you're a seasoned Linux pro or just starting out, we'll try in this section to give you a comprehensive look at the common different shells out there to help you determine the best fit for you.

Bourne Shell (sh)

The Bourne Shell is the original Unix shell created by Stephen Bourne in 1974. It was the default shell on many early distributions of Unix, and to this day it is still in widespread use, especially in shell scripting.

The sh shell is a basic and minimalistic shell, providing only a few features compared with other shells. Some of these are:

  • Looping Expressions
  • Conditional Constructs
  • Shell Functions
  • Shell Builtins
  • Shell Variables

As you can expect from a classic shell it lacks some advanced features that are expected in modern day shells such as: job control, file name completion, command editing, and command editing.

C Shell (csh)

Introduced by Bill Joy in 1978 and designed to mimic the C programing language style, the C Shell was intended for a better interactive user experience, especially after the sh shell lack in that department.

Since C Shell was tailored for friendly use to type commands in the Terminal with the minimum hassle from the user. The notable innovations that were introduced are:

  • Command History
  • Aliases
  • Tilde notation
  • Job control (Multiple background processes)
  • Path hashing
  • Filename completion

Despite these new features having proved their worth and their concepts still in use today, the C shell has some drawbacks. The most notable one is its steeper learning curve, and it was heavily criticised by experts that it's not suitable for scripting. Also, the C Shell does not support Command editing and expansions.

Korn Shell (ksh)

The ksh shell was developed in 1982 by David Korn at the AT&T Bell Laboratories and then later updated as an enhanced version called ksh93. The Korn Shell addressed the limitation of the Bourne Shell by implementing the new advantages of the C Shell.

This shell gained popularity for two reasons: the first, was mainly because it has similar syntax to the sh (most users were familiar with Bourne syntax), and the second, it implemented the C Shell features as well as some notable new capabilities:

  • Associative array data structure
  • Command inline editing experience based on vi and Emacs
  • Built-in command customizations

The Korn Shell is also with its drawbacks, for instance, the job control and scripting style are similar to the C shell's, which are less flexible, and complex. The ksh implemented filename completion but missed command completion and variable completion. Overall, you can argue that the Korn Shell surpasses the C Shell because of its inline editing interface capability.

TC Shell (tcsh)

Developed by Ken Greer in the late 1970s to implement numerous Tenex command behaviors into the C Shell. In contrast to widespread belief, tcsh is not a clone of csh but rather it was based on it. Therefore, the tcsh shell is an improved version of the C Shell.

The TC Shell is backward compatible with csh but with new improvements focused specifically on the History navigation, a programmable Command-line editing & Completion, and others like spelling correction for variables, hostnames, and filenames...

However, the tcsh shell is considered a poor scripting choice due to its complexity and steep learning curve. Also, in a shell script for both tcsh and csh, you can only use aliases instead of declaring functions, and you'll not be able to group commands. Additionally, you may find it simple to learn the TC Shell only if you know the C Shell.

Bourne Again shell (bash)

Written by Brain Fox and Chet Ramey in 1989, Bash Shell was based on the Bourne Shell, inheriting many features such as Shell Variables, Shell Built-ins, Shell Control Constructs, and many more. Bash is by far the most popular shell, it is by default the primary shell from the majority of Linux distributions, and can also be found on other operating systems.

Bash also implemented concepts from both the C Shell and Korn Shell such as Command History, Redirections, Source Command, Command-line Editing, Brace Expansion, and more. Furthermore, Bash surpassed these shells by offering more functionalities to deal with command line expansions & completions, and the Directory Stack built-in, as well as supporting regular expressions.

Even though it's relatively easy to transition from either Bourne Shell or even C Shell to Bash, it isn’t without its drawbacks. The most notable ones roam around the scripting side:

  • Not recommended for complex tasks
  • Difficult to maintain
  • Slower with complex commands
  • Syntax ambiguity ('+=' used for addition operations, adding an element to an array, or appending strings)

Z Shell (zsh)

Written by Paul Falstad in 1990, the Z Shell - just like Bash - implemented most concepts from the Korn Shel and C Shell, for the purpose be a powerful scripting and interactive shell. Although zsh and bash share many similarities for scripting and interactive use, the Z Shell stands tall when it comes to its vast array of capabilities.

The Z Shell is always praised for its customizability, making it well-suited for interactive use. The most noticeable features that set zsh from bash and other shells are:

  • Advanced Command-ling Editing
  • Easy control over multi-line commands
  • Very extended Expansions and Completions.
  • Improved and extended Globbing
  • Customizable Prompt
  • Floating-point arithmetic Support
  • Extended range of plugins and themes
  • Possibility to work with a /bin/sh Shebang

With all its features the Z Shell carries a cost: For instance, it has a steeper learning curve, being that learning all features is too difficult. Its executable is quite larger than most shells. Additionally, when compared with other shells, zsh lags behind when it comes to performance.

Friendly Interactive Shell (fish)

The Fish shell was originally authored by Axel Liljencrantz and released in 2005. It was developed with the aim to offer users with a lot of features right out of the box, rather than having to manually configure them. As well as to present users with a modern user-friendly experience to outshine traditional shells.

When it comes to modernity, Fish standout with its improved Tab completion, consistent syntax, and syntax highlighting features, as well as its gentle learning curve. Additionally, Fish has a faster performance compared to zsh, despite offering advanced features such as:

  • Auto-suggestions (automatically suggesting recent commands in light gray)
  • Man-page completions (automatically parsing man pages)
  • Modern Syntax highlighting
  • Directory awareness (suggesting only possible commands for certain directories)

Fish isn’t without its drawbacks, for instance, since Fish is not based on Bourne Shell, learning it won't help you with other Bourne-based shells. As well as, If you're using Bourne-based tools, you may need to edit some of the syntaxes to work with Fish. Finally, it's also worth noting that Bash is slightly faster.

Conclusion

The Unix shell has remained in the computer industry for over 40 years, evolving significantly with improvements but still keeping many of its original features and concepts. For instance, Bourne shell derivatives such as the Bourne Again Shell (Bash), C Shell (csh/tcsh), Z shell (Zsh), and Korn shell (Ksh) are still in widespread use to this day despite attempts to create modern and user-friendly shells like Friendly Interactive Shell (Fish). This only proves without a shadow of a doubt, the strength and versatility of the Bourne-based Shells.

Related Read: Ways to Check Which Shell You are Using on Linux

SHARE

Comments

Please add comments below to provide the author your ideas, appreciation and feedback.

Leave a Reply

Leave a Comment