Linux command shells

Unix / Linux command shells

Unix / Linux command shells

Unix and Linux command shells

Within the Unix and Linux operating systems , a command shell is an operating system service/application that takes commands from a terminal emulator program or from a script source file and performs any given commands by making calls to the provided operating system API services.

The Linux command shell is one of the main reasons why Unix and Linux remain so favored in the IT business today. The level of control and power that can be taken over a computer system using a shell script or by just typing commands from a command terminal in Unix and Linux is very high compared to a system running MS-Windows.

Large scripts can be written that can automate the editing of system and user files, perform automatic reporting of system activities and performance measurements, perform job control, application install and updates and in fact almost any task you can think of as a systems administrator can be performed using a shell environment without ever going near a mouse.

Many Unix/Linux server systems today do not have a ( keyboard, mouse or screen ) attached and thus are controlled by remote access, using a command line shell from a remote terminal thus shell text based login is much more practical.

On most Unix/linux systems these days you can install many different shells from your operating systems online application applications repository , there are several shells available. Most available shells offer similar functionality, but each has different syntax and capabilities, they include ( sh, csh, ksh, tcsh, bash, zsh and dash ).

Today’s most popular shells include bash, zsh, ksh and dash.

The oldest of the shells are sh and csh both originating from earlier version of Unix.

You can get information on the different shells installed on your system, by looking at the details held by your installed package manager i.e. apt or synaptic package manager, under shells.

In order to select a shell as your default shell, used each time you use a command line terminal. You will need to edit your user account and add the new shell as you default shell, you must logoff and login again for this change to take place.

As shells can be used as an interpreted programming languages. To automate tasks, you may write scripts containing built-in shell commands.

When you execute a script, the shell interprets these commands as if you had entered them from the command-line terminal prompt.

Compared to compiled programs in c++ for example, shell scripts are slow but as they are mainly used for system functions, such as for file operations and not for mathematical calculation or graphics then this is less of a concern that it may appear.

UNIX shells since 1977

Looking at modern shells from 1977, when the Bourne shell was introduced.

The Bourne shell, created by Stephen Bourne at AT&T Bell Labs for V7 UNIX, remains a useful shell today (in some cases, as the default root account shell). The author developed the Bourne shell after working on an ALGOL68 compiler, so you’ll find its grammar more similar to the Algorithmic Language (ALGOL) than other shells. The source code itself, although developed in C, even made use of macros to give it an ALGOL68 flavor.

The Bourne shell had two primary goals: serve as a command interpreter to interactively execute commands for the operating system and for scripting (writing reusable scripts that could be invoked through the shell). In addition to replacing the Thompson shell, the Bourne shell offered several advantages over its predecessors.

Bourne introduced control flows, loops, and variables into scripts, providing a more functional language to interact with the operating system (both interactively and noninteractively). The shell also permitted you to use shell scripts as filters, providing integrated support for handling signals, but lacked the ability to define functions.

Finally, it incorporated a number of features we use today, including command substitution (using back quotes) and HERE documents to embed preserved string literals within a script.

The Bourne shell was not only an important step forward but also the anchor for numerous derivative shells, many of which are used today in typical Linux systems.

Figure 1 illustrates the lineage of important shells. The Bourne shell led to the development of the Korn shell (ksh), Almquist shell (ash), and the popular Bourne Again Shell (or Bash). The C shell (csh) was under development at the time the Bourne shell was being released. Figure 1 shows the primary lineage but not all influences; there was significant contribution across shells that isn’t depicted.

Linix Shell timeline

Linix Shell timeline

Basic shell architecture

The fundamental architecture of a hypothetical shell is simple (as evidenced by Bourne’s shell). As you can see in Figure 2, the basic architecture looks similar to a pipeline, where input is analyzed and parsed, symbols are expanded (using a variety of methods such as brace, tilde, variable and parameter expansion and substitution, and file name generation), and finally commands are executed (using shell built-in commands, or external commands).


This entry was posted in computer fundamentals, Development Languages, Linux, Operating systems and tagged , , , , , , , , , , , , , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s