Definition and function of a shell

Source: Internet
Author: User

The shell is a special program used as an interface between the user and the heart of the operating system, a program called the kernel, the kernel is loaded into memory at boot time, and manages the system until shutdown. it creates and controls processes, manages memory, file systems, communications, and so forth. all other programs, including Shell programs, reside on the disk. the kernel loads programs from the disk into memory, executes them, and cleans up the system when they terminate. the shell is a utility program that starts up when you log on. it allows users to interact with the kernel by interpreting commands that are typed either at the command line or in a script file.

When you log on, an interactive shell starts up and prompts you for input. after you type a command, it is the responsibility of the shell to: (a) parse the command line; (B) handle wildcards, redirection, pipes, and job control; and (c) Search for the command, and if found, execute that command. when you first learn Linux, you spend most of your time executing commands from the prompt. you will be using the shell interactively.

If you type the same set of commands on a regular basis, you may want to automate those tasks. to do so, you place each command in an executable file, called a shell script. A shell script is much like a batch file. more sophisticated scripts contain programming constructs for making decisions, looping, file testing, and so forth. writing scripts not only requires learning programming constructs and techniques, but also assumes that you have a good understanding of Linux utilities and how they work. there are some utilities, such as grep, sed, and gawk, that are extremely powerful when used in scripts for the manipulation of command output and files. after you have become familiar with these tools and the programming constructs for your particle shell, you will be ready to start writing useful scripts. when executing commands from within a script, you will be using the shell as a programming language.

The three major UNIX Shells

The three prominent and supported shells on most Unix systems are the Bourne shell (at&t shell), the C shell (Berkeley shell), and The Korn shell (superset of The Bourne shell ). all three of these shells behave pretty much the same way when running interactively, but have some differences in syntax and efficiency when used as scripting languages.

The Bourne shell is the standard UNIX shell, and the shell used to administer the system. most of the system administration scripts, such as the RC Start and Stop scripts and shutdown, are Bourne shell scripts, and when in single-user mode, this is the shell commonly used by the Administrator when running as root (superuser ). this shell was written at at&t and is known for being concise, compact, and fast. the default Bourne shell prompt is the dollar sign ($ ).

The C shell, developed at Berkeley, added a number of features, such as command line history, aliasing, built-in arithmetic, filename completion, and job control. the C shell has been favored over the Bourne shell by users running the shell interactively, but administrators prefer the Bourne shell for scripting, because Bourne shell scripts are simpler and faster than the same scripts written in C shell. the default C shell prompt is the percent sign (% ).

The Korn shell is a superset of The Bourne shell written by David Korn at at&t. A number of features were added to this shell above and beyond the enhancements of the C shell. korn shell features include an editable history, aliases, functions, regular expression wildcards, built-in arithmetic, Job control, Coprocessing, and special debugging features. the Bourne shell is almost completely upward-compatible with the Korn shell, So older Bourne shell programs run fine in this shell. the default Korn shell prompt is the dollar sign ($ ).

The major Linux Shells

The shells used by Linux do not exclusively belong to the Linux operating system. they are freely available and can be compiled on any UNIX system. but when you install Linux, you will have access to the GNU shells and tools, not the standard UNIX shells and tools. although Linux supports a number of shells, the Bourne again shell (BASH) and the TC shell (tcsh) are by far the most popular. the Z shell is another Linux Shell that inates a number of features from the Bourne again shell, the TC shell, and the Korn shell. the public domain Korn shell (pdksh) a Korn shell clone, is also available, and for a fair you can get at&t's Korn shell, not to mention a host of other unknown smaller shells.

To see what shells are available under your version of Linux, look in the file,/etc/shell.

Uses of a shell

One of the major uses of a shell is to interpret commands entered at the prompt. the shell parses the command line, breaking it into words (called tokens), separated by white space, I. E ., tabs, spaces, or a newline. if the words contain special metacharacters, the shell evaluates them. the shell handles file I/O and background processing. after the command line has been processed, the shell searches for the command and starts its execution.

Another important function of the shell is to customize the user's environment, normally done in Shell initialization files. these files contain definitions for setting terminal keys and window characteristics; setting variables that define the search path, permissions, prompts, and the terminal type; and setting variables that are required for specific applications such as Windows, text-processing programs, and libraries for programming languages. the Bourne again and the TC shells also provide further customization with the addition of history and aliases, filename and command completion, spell checking, HELP features, built-in variables set to protect the user from clobbering files, inadvertently logging out, and to define y the user when a job has completed, etc.

The shell can also be used as an interpreted programming language. shell programs, also called scripts, consist of commands listed in a file. the programs are created in an Editor (although online scripting is permitted ). they consist of Linux commands interspersed with fundamental programming constructs, such as variable assignment, conditional tests, and loops. you do not have to compile shell scripts. the shell interprets each line of the script as if it had been entered from the keyboard. because the shell is responsible for interpreting commands, it is necessary for the user to have an understanding of what those commands are.

Responsibilities of the shell

The shell is ultimately responsible for making sure that any commands typed at the prompt get properly executed. Included in those responsibilities are:

  1. Reading input and parsing the command line.

  2. Evaluating special characters.

  3. Setting up pipes, redirection, and background processing.

  4. Handling signals.

  5. Setting up programs for execution.

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.