Linux Administration (15 Blogs) Become a Certified Professional
AWS Global Infrastructure

Operating Systems

Topics Covered
  • Linux Administration (14 Blogs)
  • Linux Fundamentals (1 Blogs)
  • Comprehensive Unix Shell Scripting (1 Blogs)
SEE MORE

Why do you need the different Linux Shells?

Last updated on Mar 15,2023 22.6K Views

Upasana
Research Analyst, Tech Enthusiast, Currently working on Azure IoT & Data Science... Research Analyst, Tech Enthusiast, Currently working on Azure IoT & Data Science with previous experience in Data Analytics & Business Intelligence.

Shells are like brands. Everyone has a favourite and religiously defends that choice and ever so often, tells you why you should switch. The different Types of Shells in Linux can offer various capabilities, but at their core, they’re basically implementing ideas that were developed decades ago.

So, we’ll begin with a short history of modern shells, and then explore some of the useful, open source shells available for Linux today and you can decide for yourself how beneficial it would be for you to Learn Linux.

Following will be the course of discussion in this blog;

 

Evolution of Shells

Beyond the Thompson shell, we begin our look at modern shells.

1977

The Bourne shell was introduced. The Bourne shell(sh), by Stephen Bourne at AT&T Bell Labs for V7 UNIX, remains a useful shell today (in some cases, as the default root shell). The Bourne shell was developed after working on an ALGOL68 compiler, so its grammar is more along the lines of Algorithmic Language (ALGOL) than other shells. The source code was developed in C.

The Bourne shell served two primary goals:

  • Executing UNIX/Linux commands for the operating system,i.e, command line interpreter
  • Writing reusable scripts that could be invoked through the shell,i.e, scripting

In addition to replacing the Thompson shell, the Bourne shell offered many other advantages over its predecessors such as control flows, loops, and variables into scripts, providing a more functional language to interact with the operating system.

The shell also permitted you to use shell scripts as filters, providing integrated support for handling signals but lacked the ability to define functions.

It introduced the world to a number of features that we use today, like command substitution and HERE documents to embed preserved string literals within a script.

The Bourne shell led to the development of the many shells that we use today.

1978

The C shell(csh) was developed by Bill Joy with the objective of achieving a scripting language similar to C programming language. This was useful given that C was a primary language in use back then which also made it easier and faster to use.

1983

Developed by David Korn, the Korn Shell(ksh) combined features of both Bourne Shell and C Shell. It is backward-compatible with the Bourne Shell. It included features from the C Shell such as job control, command aliasing & command history.

Also in the same year, the TENEX C Shell(tcsh) was introduced. It started out as a derivative of the C Shell but with a programmable command line completion and editing features added to it.

1989

One of the most widely used shells today, the Bourne-Again Shell (bash) was written by Brian Fox for the GNU project as a pre-software replacement for the Bourne Shell. It showed all features from the Bourne shell but is much more efficient and easy to use.

It supported filename globbing, piping, command substitution, and control structures for conditional testing and iteration.

Evolution of Linux Shells - Types of Shells in Linux - Edureka

Present Day

Many shells were evolved later such as Public Domain Korn Shell, Almquist Shell and the Extensible Shell bringing in new features and dialects of their own suitable for different needs.

Definition of the Shell

Shell is an interactive environment which provides an interface to an Operating System. It gathers input from you in a sequence to implement a specific use model.

Basic Architecture of the Shell

Shell Architecture - Types of Shells in Linux - Edureka

The fundamental architecture on which the hypothetical Shell is based isn’t complex. The basic architecture is pretty similar to a pipeline, where input is analyzed and parsed, symbols are expanded. It uses a variety of methods such as brace, tilde, variable and parameter expansion and substitution, and filename generation. Then, commands are executed using shell built-in commands, or external commands.

Different Types of Shells in Linux and Why Should You Choose Them

Each of these shells has its own flavour and is meant for people seeking solutions to different problems. You can see how similar or dissimilar these popular shells are from each other through their respective scripts which are written to perform the same task,i.e, finding all executable files.

1. Bourne-Again Shell

Bash stands for Bourne Again Shell and it is the default shell on many Linux distributions today. It is also a sh-compatible shell and offers practical improvements over sh for programming and interactive use which includes:

  • Command line editing
  • Job Control
  • Unlimited size command history
  • Shell Functions and Aliases
  • Unlimited size Indexed arrays
  • Integer arithmetic in any base from two to sixty-four

Code Example 

#!/bin/bash
#find all executables

count=0

#Test arguments
if [ $#‑ne 1 ] ; then
echo "Usage is $0 <dir>"
exit 1
fi

#Ensure argument is a directory
if [ ! ‑d "$1" ] ; then
echo "$1 is not a directory."
exit 1
fi

#Iterate the directory, emit executable files
for filename in "$1"/∗
do
if [ ‑x "$filename" ] ; then
echo $filename
count=$((count+1))
fi
done

echo
echo "$count executable files found."

exit 0

If you’re new to shell scripting, bash is a great language, to begin with. It is interactive and well rounded. As its name implies, Bash is a superset of the Bourne shell, and you can run most Bourne scripts without changing them. It is the language taught throughout universities and schools to students studying Computer Science.

2. TENEX C Shell

Tcsh is enhanced C shell, it can be used as an interactive login shell and shell script command processor.

Tcsh has the following features:

  • C like syntax
  • Command-line editor
  • Programmable word and filename completion
  • Spelling correction
  • Job control

Code Example 

#!/bin/tcsh
#finding all executable files

set count=0

#Testing arguments
if ($#argv != 1) then
echo "Usage is $0 <dir>"
exit 1
endif

#Ensuring each argument is a directory
if (! ‑d $1) then
echo "$1 is not a directory."
exit 1
endif

#Iterating the directory, printing executable files
foreach filename ($1/∗)
if (‑x $filename) then
echo $filename
@ count = $count + 1
endif
end

echo
echo "$count executable files found."

exit 0

If you are a network or systems administrator in a Unix environment, you will almost certainly run into the C shell, so it is good to at least have some familiarity with it.

3. Korn Shell

Ksh stands for Korn shell and was designed and developed by David G. Korn. It is a complete, powerful, high-level programming language and also an interactive command language just like many other Unix/GNU Linux shells.

The Korn shell includes features from other shells and  provides several more advanced features found in modern scripting languages such as;

    • associative arrays 
    • floating point arithmetic
    • job control
    • command aliasing
    • command history
    • supports POSIX standards
    • backward compatibility with bash

Code Example 

#!/usr/bin/ksh
#finding all executable files

count=0

#Testing arguments
if [ $#‑ne 1 ] ; then
echo "Usage is $0 <dir>"
exit 1
fi

#Ensuring each argument is a directory
if [ ! ‑d "$1" ] ; then
echo "$1 is not a directory."
exit 1
fi

#Iterating the directory, printing executable files
for filename in "$1"/∗
do
if [ ‑x "$filename" ] ; then
echo $filename
count=$((count+1))
fi
done

echo
echo "$count executable files found."

exit 0

This Shell is a Unix shell programming language you can use interactively to execute commands from the command line or programmatically to create scripts that can automate many computer maintenance and system administration tasks.

4. Z Shell

Zsh is designed to be interactive and it incorporates many features of other Unix/GNU Linux shells such as bashtcsh, and ksh.

It is also a powerful scripting language just like the other shells available. Though it has some unique features that include:

  • Filename generation
  • Startup files
  • Login/Logout watching
  • Closing comments
  • Concept index
  • Variable index
  • Functions index
  • Key index and many more that you can find out in man pages

Code Example 

#!/bin/zsh
#finding all executable files

set count=0

#Testing arguments
if ($#argv != 1) then
echo "Usage is $0 <dir>"
exit 1
endif

#Ensuring each argument is a directory
if (! ‑d $1) then
echo "$1 is not a directory."
exit 1
endif

#Iterating the directory, printing executable files
foreach filename ($1/∗)
if (‑x $filename) then
echo $filename
@ count = $count + 1
endif
end

echo
echo "$count executable files found."

exit 0

5. Scheme Shell

The Scheme shell (scsh) is an exotic shell that offers a scripting environment using Scheme, which is a derivative of the Lisp language. The Pyshell is an attempt to create a similar script that uses the Python language.

Code Example 

#!/usr/bin/scsh ‑s
!#

(define argc
(length command‑line‑arguments))

(define (write‑ln x)
(display x)
)

(define (showfiles dir)
(for‑each write‑ln
(with‑cwd dir
(filter file‑executable? (directory‑files "." #t)))))

(if (not (= argc 1))
(write‑ln "Usage is fae.scsh dir")
(showfiles (argv 1)))

The script may appear foreign, but it implements similar functionality to the scripts provided thus far. This script includes three functions and directly executable code at the end to test the argument count. I’d like to draw your attention to the showfiles function, which iterates a list, calling write-ln after each element of the list. This list is generated by iterating the named directory and filtering it for files that are executable.

Alternative shells can be used depending upon your requirements/taste.

You can refer to this video to know the different shells in Linux and how they’re run in this video;

Different Shells In Linux | Bash vs C Shell vs Korn Shell | Linux Certification Training | Edureka

This video talks about the origin and evolution of different Linux shells and draws a parallel between three of the most basic shells by a demonstration on the terminal.

These are the different types of shells in Linux that have remained the same almost after 35 years after their inception—a tremendous testament to the original developers of the early shells. In an industry that continually reinvents itself, the original shell has proven time after time to be substantial. Despite having been improved upon through the years, the basic concept of the shell still hasn’t changed. 

If you wish to learn Linux Administration and build a colorful career, then check out our Linux Administration Course which comes with instructor-led live training and real-life project experience.

Comments
0 Comments

Join the discussion

Browse Categories

webinar REGISTER FOR FREE WEBINAR
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP

Subscribe to our Newsletter, and get personalized recommendations.

image not found!
image not found!

Why do you need the different Linux Shells?

edureka.co