Basic knowledge of Shell in Centos

Source: Internet
Author: User
Tags add numbers
What is Shell? Shell is a program with special functions. It is an interface between the user and the core program (kernel) of the UNIX/Linux operating system. Why do we say shell is an intermediary between the core program of the system and the user? Readers who have read the introduction to the operating system know that the operating system is a manager and distributor of system resources. When you have requirements, you must submit them to the system. From the operating system perspective, it must also prevent system damage caused by incorrect operations? What is Shell?

Shell is a program with special functions. It is an interface between the user and the core program (kernel) of the UNIX/Linux operating system. Why do we say shell is an intermediary between the core program of the system and the user? Readers who have read the introduction to the operating system know that the operating system is a manager and distributor of system resources. When you have requirements, you must submit them to the system. From the operating system perspective, it must also prevent system damage caused by incorrect operations? As we all know, commands on a computer can be converted into binary code through command or program. What about commands? In fact, shell is also a program that reads commands from the input device, converts them into mechanical codes that computers can understand, and then executes them.
Various operating systems have their own shells. For example, in DOS, its shell is command.com? N. For example, different command interpreter programs such as NDOS, 4DOS, and DRDOS in DOS can replace the standard command.com, except for the Bourne shell (/bin/sh) in UNIX) C shell (/bin/csh), Korn shell (/bin/ksh), Bourne again shell (/bin/bash), Tenex C shell (tcsh )... And other shells. In UNIX/Linux, the shell is independent of the core program, making it like an ordinary application, you can modify, update, or add new features without affecting the operating system.

Shell Activation

When the system starts, the core program is loaded with memory to manage the system until the system is closed. It establishes and controls processing programs, manages memory, file systems, communications, and so on. Other programs, including shell programs, are stored on disks. Core Programs load them into memory, execute them, and clean up the system after they are aborted. Shell is a utility that starts when you check in. By interpreting commands entered by users (by command columns or command files), Shell provides the ability for users to communicate with core programs.
When you sign in (login), an interactive shell starts and prompts you to enter the command. After you type a command, it is followed by shell's work. It will:
1. syntax analysis command Column
2. wildcards, redirection, pipeline, and job control)
3. Search for and execute commands
When you first learn UNIX/Linux systems, most of your time is spent executing commands under the prompt.
If you often enter a group of commands in the same form, you may want to automatically execute those tasks. In this way, you can put some commands into a file (called a command file or script) and then execute this file. A shell command file is like a batch under DOS? N (such as Autoexec. bat): It stores a series of UNIX commands into a file and then executes the file. Mature command files also support control structures of several modern programming languages, such as conditional judgment, loops, file testing, and transfer parameters. To write a command file, you must not only learn the structure and skills of program design, but also have a deep understanding of UNIX/Linux utilities and how they work. Some utilities are very powerful (such as grep, sed, and awk) and are often used in command files to manipulate command output and files. After you become familiar with those tools and program design structures, you can start to write command files. When the command is executed by the command file, you have used shell as the program language. Let's talk about Shell's life

First, it is important that the standard UNIX shell is V7 (AT&T's seventh edition) UNIX, which was proposed at the end of 1979 and named after its creator Stephen Bourne. The Bourne shell is designed based on the language Algol and is mainly used for automated system management. While Bourne shell is popular for simplicity and speed, it lacks many conversational usage features, such as history, alias, and work control.
C shell was developed in the late 1970s s at the University of California, berkelai, and is released in part of 2BSD UNIX. This shell is mainly written by Bill Joy and provides some additional features that are invisible to the standard Bourne shell. C shell is based on the C program language and is used to share similar syntaxes when the program language is used. It also provides improvements in interactive application, such as command column history, alias, and work control. Because C shell is designed on a large machine and some additional functions are added, C shell runs slowly on a small machine, even on large machines, it seems slower than the Bourne shell.
With the Bourne shell and C shell, UNIX users have a choice and it is better to argue that shell. AT&T's David Korn invented the Korn shell in the middle of 1980s. It was released in 1986 and became part of the official SVR4 UNIX in 1988. The Korn shell is actually a superset of The Bourne shell. It can be executed not only on UNIX systems, but also on OS/2, VMS, and DOS. It provides upward compatibility with the Bourne shell, and adds many popular features on the C shell, increasing the speed and efficiency. The Korn shell has undergone many revisions. To find the version you are using, press Ctrl-v under the ksh symbol.

Three main Shells and their branches

In most UNIX systems, the three well-known and widely supported shells are Bourne shell (AT&T shell, BASH in Linux) and C shell (Berkeley shell, TCSH in Linux) and Korn shell (the superset of The Bourne shell ). The three shells in the interactive mode behave similarly, but as a command file language, the syntax and execution efficiency are somewhat different.
The Bourne shell is a standard UNIX shell, which was often used as a management system. Most of the system management command files, such as rc start, stop, and shutdown, are the Bourne shell command files, and in single user mode) it is often used by system administrators when checked in as root. The Bourne shell is developed by AT&T and is famous for its simplicity and speed. The default value of the Bourne shell prompt symbol is $.
C shell is developed by Berkeley and has added some new features, such as command history and alias (alias), built-in arithmetic, filename completion, and job control ). For users who often execute shell in conversation mode, they prefer to use C shell, but for system managers, they prefer to use the Bourne shell as the command file because of the Bourne shell command? N is simpler and faster than the C shell command file. The default value of the C shell prompt symbol is %.
Korn shell is a superset of The Bourne shell, developed by David Korn of AT&T. It adds some features and is more advanced than C shell. Features of the Korn shell include editable history, alias, function, regular expression wildcard, built-in arithmetic, job control, and coprocessing) and special debugging functions. The Bourne shell is almost fully compatible with the Korn shell (upward compatible), so programs developed under the Bourne shell can still be executed on the Korn shell. The default value of the Korn shell prompt symbol is $. In Linux, The Korn shell is called pdksh, which refers to the Public Domain Korn Shell.
In addition to poor execution efficiency, the Korn shell is better in many aspects than the Bourne shell. However, it is difficult to compare the Korn shell with the C shell because both have their own strengths in many aspects, in terms of efficiency and ease of use, the Korn shell is superior to the C shell. I believe many users have a negative impression on the execution efficiency of the C Shell.
In terms of shell syntax, the Korn shell is close to the general programming language, and it has subprograms and provides more types of data. As for the Bourne shell, it has the least Data Types among the three shells and only provides string variables and Boolean types. In the overall consideration, the Korn shell is the performer among the three, followed by the C shell, and finally the Bourne shell. However, there are still other factors to consider in actual use, for example, speed is the most important choice, and it is likely to adopt the Bourne shell, because it is the most basic shell and the fastest execution speed.
Tcsh is a free software developed in recent years (the C shell in Linux actually uses tcsh) for execution. It is not a UNIX standard, but can be downloaded from many places. If you are a supporter of C shell, I suggest you try tcsh, because you can at least use it as a C shell. If you are willing to spend some time learning, you can also enjoy many of its new advantages, such:
1. tcsh provides a command line editing program.
2. Provides the command column complementing function.
3. the spelling correction function is provided. It can automatically detect the command or word that is spelling incorrectly in the Command column.
4. Dangerous command detection and reminder function, to prevent you from accidentally executing the rm * command which is highly lethal.
5. Provides a shortcut for Common commands ). Bash is backward compatible with the Bourne shell and incorporates many functions of C shell and Korn shell. These functions are actually available in C shell (including tcsh, of course), but they were not supported by Bourne shell in the past. Below I will introduce bash's six important improvements (detailed instructions for use I will introduce them in a later chapter ):
1. job contorl ). Bash supports signals and instructions about work, which will be mentioned later in this chapter.
2. Alias function (aliases ). The alias command is used to create another name for a command. It operates like a macro and expands into the commands it represents. The alias does not replace the command name. It only gives that command another name.
3. command history ). BASH shell is added to the command history function provided by C shell. It records the commands you recently executed using the history tool. The command starts from 1. The default value is 500. The history tool program is a short-term memory that records your recent commands. To view these commands, you can type history in the Command column. This will display the list of recently executed commands and add numbers in front.
Each of these commands is technically called an event. The event describes an action that has been taken (the executed command ). Events are numbered according to the execution order. The closer an event is, the larger the number it is. These events are identified by its number or command prefix. The history utility allows you to place an event in the Command column and allow you to execute it by referring to the previous event. The simplest way is to place a history event on your command column at a time with the up/down key; you do not need to display the list with history first. One up key will place the last history event in your command column, and another one will place the next history event. Press the down key to place the previous event in the Command column.
4. Command column editing program. The BASH shell command column editing capability is built in, allowing you to easily modify the command you entered before execution. If you entered the command incorrectly, you do not need to re-enter the entire command. You only need to use the Edit function to correct the error before executing the command. This is especially suitable for commands that use lengthy path names as parameters. The command column editing job is a part of the Emacs editing command. You can use Ctrl-F or right-click to move a character forward, Ctrl-B or left-click to move a character back. The Ctrl-d or DEL key deletes the character at which the cursor is currently located. To add text, you only need to move the cursor to the place where you want to insert the text and type a new character. At any time, you can press ENTER to execute the command.
5. allow the user to customize the buttons.
6. More variable types, commands, and control structures are provided to shell.
 
Bash and tcsh can be downloaded from many websites for free. They are similar in nature. They integrate their previous generation of products and then add new features, these new features mainly focus on strengthening shell programming capabilities and enabling users to customize their preferred job environments. In addition to the five shells mentioned above, zsh is also a shell widely used by UNIX programmers and advanced users. zsh is basically an extension of the Bourne shell function.
Use of Shell
No matter which Shell is used, its main function is to interpret the commands entered by the user under the command column prompt symbol. The Shell syntax analyzes the command column and splits it into tokens separated by spaces. The blank space includes the tab, blank, and New Line ). If these words contain metacharacter, shell evaluates (evaluate) their correct usage. In addition, shell also manages file input/output and background processing ). After the command column is processed, shell searches for commands and starts to execute them.
Another important function of Shell is to provide a personalized user environment, which is usually completed in the shell initialization file (. profile,. login,. cshrc,. tcshrc, and so on ). These files include setting terminal keyboard and defining window features; setting variables, defining search paths, permission limits, prompt symbols and terminal shapes; and setting variables required by special applications, such as window, text processing program, and link library of programming language. The Korn shell and C shell enhance the individualized ability to add processes, aliases, and built-in variable sets to Prevent Users From mistakenly killing files, accidentally checking out files, and notifying users when their work is completed.
Shell can also be interpreted as an interpreted programing language ). A Shell program is usually called a command file. It consists of commands listed in the file. This program is edited in the editor (although you can write the program directly in the Command column, online scripting). It consists of UNIX Commands and BASIC Program structures, for example, variables, test conditions, and loops. You do not need to compile shell commands? N. Shell interprets each line in the command file, just as it is input by the keyboard. Shell is responsible for interpreting commands, and users must understand what these commands can do. The index in this book lists some useful commands and their usage methods.

Functions of Shell

To ensure that the command entered under any prompt symbol can be properly executed. Shell has the following roles:
1. Read the input and syntax analysis command Columns
2. Evaluate special characters
3. Establish pipelines, redirection, and background handling
4. processing signals
5. Set up a program 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.