Shell in Operating System

Learn via video courses
Topics Covered

Overview

The interface to the operating system you are using is what shell is. It is the outermost layer in an operating system. It incorporates a (usually high-level) programming language to control files and processes, manage other programs, etc. The shell establishes and regulates the interaction between the operating system and you the user.

Shells thus enable a user to communicate effectively with the operating system, which is conducted either by the means of shell scripting or interactively with help of real-time keyboard input. A shell script is a file that contains a sequence of operating system commands and shell commands.

What is a Shell in an Operating System?

Shell is a computer application software that the services of an operating system to an external user or another program. Depending on the computer's particular operation and role, its shell may have either a command line interface (C.L.I.) or a graphical user interface (G.U.I.). As suggested by the name, the shell is the outermost layer in an operating system.

Shells in most operating systems are not direct interfaces to the kernel that lies beneath, even if the shell communicates with the program or user through peripheral devices directly attached to the computer system. A shell is precisely software that uses the kernel API in a manner the same as is used by other software programs. The shell also manages the interaction between the system and the user by taking user input, evaluating it, and eventually dealing with the output. Since it is an application program, in most operating systems the shell can easily be replaced with some other similar application.

layer-of-operating-system

How Does the Shell in the Operating System Work?

A shell reads standard input from as well as passes the standard output and/or the standard error to the terminal. The terminal is an application program that enables a user to access and use a shell in the operating system. This is the default behavior of a shell, however, it can be altered by using tools and techniques such as piping, streams, redirection, etc. The shell is line-oriented which means that it does not execute the commands given to it until the <Enter> key is not pressed. Pressing the enter key indicates to the terminal as well as the shell that the entire command has been typed and its execution can and should begin.

User may correct their typing as they type. Different shells have different facilities for editing the typed commands. But most of them generally identify <Bksp> (backspace) or <Del> (delete) as the keystroke for removing the last typed character. When enter is pressed, the shell evaluates the line that has been entered. After that, the shell begins the execution of the commands on that very line. The procedure that is followed is as:

  • The shell partitions the line into what is referred to as tokens. A token is a variable, command, or some other symbol that the shell recognizes. The process of building a sequence of tokens is continued until a reserved function name, a keyword (an internal command in the shell that dictates the control flow of a shell script), or an operator (any symbol that denotes a command separator, pipe, any logical condition, or any other operation the execution which can not be begun until the preceding command is interpreted) is formed.
  • The shell organizes the tokens into three categories:
    • I/O Redirection These are commands that determine where the input of a program is to be derived from or where the output of command execution is to be directed.
    • Variable Assignment These are commands that assign some value to any variable.
    • Miscellaneous Commands This category includes all the other commands. Other tokens are checked to determine whether or not they are aliases. This process is started with the first command. If it is found to be an alias, it is then replaced with the value (meaning) corresponding to the alias. If the command is not an alias or if it is followed by a whitespace character before the next command, the steps of alias checking are repeated so long as either there remain any commands, or until an alias has been recognized that is not followed by a space.
  • The commands are then executed, as one of the following:
    • External Programs if the shell locates an executable file of the same name as the command.
    • Internal Shell Commands that make the shell take some action.

shell-commands

Types of Shells in Operating Systems

A shell is either of the following two types:

1. Bourne Shell

It is sub-categorized as follows:

a. Bourne shell (sh) b. Korn shell (KSH) c. Bourne Again shell (bash) d. POSIX shell (sh)

2. C Type

It is sub-categorized as follows:

a. C shell (csh) b. TENEX/TOPS C shell (tcsh)

Example of Shell in Operating System

Microsoft Windows

Microsoft Windows has the Windows Shell.

MacOS

TCSH It is a variant of CSH(C shell). The syntax in TCSH is similar to that of the C programming language.

BASH It stands for Bourne Again Shell and is one of the most common shells.

ZSH ZSH (Z shell) is relatively new and attempts to bring the good features of bash and tcsh under a common roof, while also adding extra functionality of its own.

Linux

Linux supports all the shells that MacOS supports, namely, ZSH, BASH, and TCSH. Apart from them, Linux also supports many other shells such as the Korn shell (KSH), Bourne shell (SH), and C shell (CSH).

examples-of-shell-in-os

Advantages of Shell in OS

The following are some benefits of having a shell in an os:

  • A shell facilitates communication between the operating system and the user (or other programs).
  • A shell provides the user with a high-level syntactical language to use for executing commands.
  • A shell also provides multiple choices for taking input from or giving output.
  • A shell also supports executing scripts.
  • A shell can also be used for automation purposes.
  • A shell enables a user to use a remote computer.
  • A shell displays information in greater detail as compared to a GUI.

Disadvantages of Shell in OS

  • Shell adds a layer to the structure of an operating system.
  • Shell is not as simple to use as a GUI.
  • Shells require a beginner to learn and practice to be able to use a shell efficiently and harness its true potential.

Conclusion

  • The interface to the operating system you are using is what shell is. It is the outermost layer in an operating system.
  • A shell script is a file that contains a sequence of operating system commands and shell commands.
  • A shell may have either a command line interface (C.L.I.) or a graphical user interface (G.U.I.).
  • A shell reads standard input from as well as passes the standard output and/or the standard error to the terminal. The terminal is an application program that enables a user to access and use a shell in the operating system.
  • The shell organizes the tokens into three categories: I/O redirection, variable assignment, and miscellaneous commands.
  • Shells are of two types: Bourne shells and C shells.