0% found this document useful (0 votes)
191 views

Unit-5 Shell Programming

The document discusses different shells available in Linux operating systems. It describes the Bourne shell, C shell, Korn shell, GNU Bourne-Again shell, and Z shell, covering their key features and uses. The document also compares the C shell and Bourne Again shell.

Uploaded by

Linda Brown
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
191 views

Unit-5 Shell Programming

The document discusses different shells available in Linux operating systems. It describes the Bourne shell, C shell, Korn shell, GNU Bourne-Again shell, and Z shell, covering their key features and uses. The document also compares the C shell and Bourne Again shell.

Uploaded by

Linda Brown
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 11

Unit V

Shell Programming

The shell is a program that takes commands from the keyboard and


gives them to the operating system to perform. ... On
most Linux systems a program called bash (which stands for Bourne
Again SHell, an enhanced version of the original Unix shell program,
sh , written by Steve Bourne) acts as the shell program.

Shells are an important part of any Linux user session. We are provided several
different types of shells in Linux to accomplish tasks. Each shell has unique
properties. Hence, there are many instances where one shell is better than the other
for specific requirements.

This makes it important for us to be aware about the different types of shells
available in Linux. In this tutorial, we will discuss what is a shell and why is it
important.

Whenever a user logs in to the system or opens a console window, the kernel runs a
new shell instance. The kernel is the heart of any operating system.

It is responsible for the control management, and execution of processes, and to


ensure proper utilization of system resources.

A shell is a program that acts as an interface between a user and the kernel. It
allows a user to give commands to the kernel and receive responses from it. Through
a shell, we can execute programs and utilities on the kernel. Hence, at its core, a
shell is a program used to execute other programs on our system.

Being able to interact with the kernel makes shells a powerful tool. Without the
ability to interact with the kernel, a user cannot access the utilities offered by their
machine’s operating system.

Let’s understand the major shells that are available for the Linux environment.

Different Types of Shells in Linux


If you now understand what a kernel is, what a shell is, and why a shell is so
important for Linux systems, let’s move on to learning about the different types of
shells that are available.

Each of these shells has properties that make them highly efficient for a specific type
of use over other shells. So let us discuss the different types of shells in Linux along
with their properties and features.

1. The Bourne Shell (sh)

Developed at AT&T Bell Labs by Steve Bourne, the Bourne shell is regarded as the
first UNIX shell ever. It is denoted as sh. It gained popularity due to its compact
nature and high speeds of operation.

This is what made it the default shell for Solaris OS. It is also used as the default
shell for all Solaris system administration scripts. Start reading about shell scripting
here.

However, the Bourne shell has some major drawbacks. 

 It doesn’t have in-built functionality to handle logical and


arithmetic operations.
 Also, unlike most different types of shells in Linux, the Bourne
shell cannot recall previously used commands.
 It also lacks comprehensive features to offer a proper interactive
use.

The complete path-name for the Bourne shell is /bin/sh and /sbin/sh. By default,
it uses the prompt # for the root user and $ for the non-root users.

2. The GNU Bourne-Again Shell (bash)

More popularly known as the Bash shell, the GNU Bourne-Again shell was designed
to be compatible with the Bourne shell. It incorporates useful features from different
types of shells in Linux such as Korn shell and C shell.
It allows us to automatically recall previously used commands and edit them with
help of arrow keys, unlike the Bourne shell.

The complete path-name for the GNU Bourne-Again shell is /bin/bash. By default,
it uses the prompt bash-VersionNumber# for the root user and bash-
VersionNumber$ for the non-root users.

3. The C Shell (csh)

The C shell was created at the University of California by Bill Joy. It is denoted as
csh. It was developed to include useful programming features like in-built support
for arithmetic operations and a syntax similar to the C programming language.

Further, it incorporated command history which was missing in different types of


shells in Linux like the Bourne shell. Another prominent feature of a C shell is
“aliases”.

The complete path-name for the C shell is /bin/csh. By default, it uses the
prompt hostname#  for the root user and hostname% for the non-root users.

4. The Korn Shell (ksh)

The Korn shell was developed at AT&T Bell Labs by David Korn, to improve the
Bourne shell. It is denoted as ksh. The Korn shell is essentially a superset of the
Bourne shell.

Besides supporting everything that would be supported by the Bourne shell, it


provides users with new functionalities. It allows in-built support for arithmetic
operations while offereing interactive features which are similar to the C shell.

The Korn shell runs scripts made for the Bourne shell, while offering string, array
and function manipulation similar to the C programming language. It also supports
scripts which were written for the C shell. Further, it is faster than most different
types of shells in Linux, including the C shell.

The complete path-name for the Korn shell is /bin/ksh. By default, it uses the
prompt #  for the root user and $ for the non-root users.
5. The Z Shell (zsh)

The Z Shell or zsh is a sh shell extension with tons of improvements for


customization. If you want a modern shell that has all the features a much more,
the zsh shell is what you’re looking for.

Some noteworthy features of the z shell include:

 Generate filenames based on given conditions


 Plugins and theming support
 Index of built-in functions
 Command completion
 and many more…

Let us summarise the different shells in Linux which we discussed in this tutorial in
the table below.

Complete Prompt for root Prompt for non root


Shell
path-name user user

/bin/sh and
Bourne shell (sh) # $
/sbin/sh

GNU Bourne- bash- bash-


/bin/bash
Again shell (bash) VersionNumber# VersionNumber$

C shell (csh) /bin/csh # %

Korn shell (ksh) /bin/ksh # $

Z Shell (zsh) /bin/zsh <hostname># <hostname>%

Wrapping up

Shells are one of, if not the most powerful tools available to a Linux user. Without
shells, it is practically impossible for a person to utilise the features and
functionality offered by the kernel installed on their system.

While we covered only the most commonly used types of shells in Linux, there are
many other shell types worth exploring.
We hope this tutorial was able to help you to get understand the concept of shells,
along with the properties of the different types of shells in Linux. If you have any
feedback, queries, or suggestions, feel free to reach out to us in the comments
below.

Difference between C shell and Bourne shell

CSH is C shell while BASH is Bourne Again shell. ... C shell and


BASH are both Unix and Linux shells. While CSH has its own
features, BASH has incorporated the features of
other shells including that of CSH with its own features which
provides it with more features and makes it the most widely used
command processor

CSH vs BASH

Computers need operating systems in order for them


to be able to run several programs. They are the
programs that recognize what computer users type
on their keyboards and send and display these on
their computer screens.

They control devices that are attached and used with


the computer such as printers and compact disks,
and they manage the files and other data that are on
the disks. They make the computer run smoothly
even if several programs are running, and they keep
the system secure.
There are several operating systems available like
Windows, DOS, and Linux. Each operating system
in turn has a command processor which executes its
commands. Thus, when a user types a command,
the command processor is the part of the operating
system that accepts it. It will verify the validity of the
command and will execute it if it is a valid command
or gives an error warning if it is not. DOS and
Windows operating systems have command.com
operating systems while Unix and Linux operating
systems have the C shell (CSH), the Bourne shell,
and the Bourne Again shell (BASH).

The C shell (CSH) is a command processor which


runs on a text window and causes action when a
user types a command. It is a Unix shell which was
developed by Bill Joy in the late 1970s with the help
of Michael Ubell, Mike O’Brien, Jim Kulp, and Eric
Allman.

It can read scripts and do several other functions


such as supporting command substitution, the
wildcarding of file names, control structures,
documents, and variables. It incorporates job control
with C syntax, history mechanism, and interactive
completion of file names and user names. Aside from
being a shell script command processor, it is also
used as an interactive login shell.

Bourne Again shell (BASH) is also a command


processor that runs on a text window just like other
Linux shells. It was developed as a replacement for
the Bourne shell by Brian Fox for use on the GNU
operating system. It was released in 1989 and
combines the features of CSH, KSH, and SH. The
keywords and syntax that it uses are from SH which
have many extensions unlike the original Bourne
shell. Its command line editing, command history,
command substitution, and directory are from KSH
and CSH.

BASH evidently has more features than CSH since it


has the features of all other shells in addition to its
own. It is also more suitable for use by beginners,
and learning it will introduce users to the other
shells since their features are also being used by
BASH.

Summary:

1.CSH is C shell while BASH is Bourne Again shell.


2.C shell and BASH are both Unix and Linux shells.
While CSH has its own features, BASH has
incorporated the features of other shells including
that of CSH with its own features which provides it
with more features and makes it the most widely
used command processor.
3.CSH was developed by Bill Joy in the late 1970s
while BASH was developed by Brian Fox.
Introduction to Linux Shell and
Shell Scripting
If you are using any major operating system you are
indirectly interacting to shell. If you are running Ubuntu,
Linux Mint or any other Linux distribution, you are
interacting to shell every time you use terminal. In this
article I will discuss about linux shells and shell scripting so
before understanding shell scripting we have to get familiar
with following terminologies –
 Kernel
 Shell
 Terminal
What is Kernel
The kernel is a computer program that is the core of a
computer’s operating system, with complete control
over everything in the system. It manages following
resources of the Linux system –
 File management
 Process management
 I/O management
 Memory management
 Device management etc.
It is often mistaken that Linus
Torvalds has developed Linux OS, but
actually he is only responsible for
development of Linux kernel.
Complete Linux system = Kernel
+ GNU system utilities and libraries +
other management scripts + installation
scripts.
What is Shell

• A shell is special user program which


provide an interface to user to use
operating system services. Shell accept
human readable commands from user
and convert them into something which
kernel can understand. It is a command
language interpreter that execute
commands read from input devices such
as keyboards or from files. The shell gets
started when the user logs in or start the
terminal.

• Shell is broadly classified into two


categories –
Command Line Shell
Graphical shell
• Command Line ShellShell can be accessed
by user using a command line interface.
A special program called Terminal in
linux/macOS or Command Prompt in
Windows OS is provided to type in the
human readable commands such as
“cat”, “ls” etc. and then it is being
execute. The result is then displayed on
the terminal to the user. A terminal in
Ubuntu 16.4 system looks like this –

n above screenshot “ls” command with “-
l” option is executed.
It will list all the files in current working directory in
long listing format.
Working with command line shell is bit difficult for
the beginners because it’s hard to memorize so many
commands. It is very powerful, it allows user to store
commands in a file and execute them together. This
way any repetitive task can be easily automated.
These files are usually called batch files in Windows
and Shell Scripts in Linux/macOS systems.
Graphical Shells
Graphical shells provide means for manipulating
programs based on graphical user interface (GUI), by
allowing for operations such as opening, closing,
moving and resizing windows, as well as switching
focus between windows. Window OS or Ubuntu OS
can be considered as good 

• example which provide GUI to user for


interacting with program. User do not
need to type in command for every
actions.A typical GUI in Ubuntu system –

GUI shell

You might also like