Author: Rick Rummel describes the many things you can do without having to know how they actually work. For example, you don't have to know how to use the physical principle of engine combustion. Lack of electronic knowledge will not prevent you from listening to music with CD. I don't know what shell and its working principle, you can still use UNIX. However, you know that you can better utilize UNIX. A UNIX system has three representative shells available: Bourne Shell, Korn Shell, C shells. They will be discussed at 11, 12, 13. In this chapter, you will learn: What is the shell shell to do what shell and the relationship between the entire system protect its internal core with Shell nuts, and a UNIX Shell provides a peripheral protection layer. When you start a UNIX-based computer, UNIX programs are transferred to the computer's memory until you are shut down. This program is called kernel, which performs many underlying and system levels. The kernel has a responsibility to explain the basic instructions and send them to the processor. The kernel is also responsible for running and scheduling processes, as well as performing all input outputs. The kernel is the heart of the UNIX system, and there is only one inner core. You may have a bit confusing to kernel duties, while kernel instructions are the same complexity and high technical. In order to protect the kernel's complexity, it is also a housing (shell) around the kernel to protect the kernel to protect the kernel to prevent the kernel. The user makes a request to the shell, the shell explains and transmits the request to the kernel. The remaining part of this section explains how this outer layer is established. Once the kernel is transferred into memory, he is ready to execute the user's request. However, the user first has to connect to the login and issue a request. Anyway, the user logs in, the kernel must know who the user and how to talk to him. To do this, the kernel calls two special programs, getty and login. Corresponding to each user's login point - commonly referred to as a TTY-core calling Getty program. This process is called spawning (spawn is a spawning). GETTY displays a login prompt, which continuously monitors the input point waits for the username. When getty gets any input, it calls the Login program. Login establishes the user's identity and verifies the right to log in. The Login program checks the Password file. If the password entered by the user is incorrect, the control will return from the login point to getty. If it is correct, login calls the program recorded in the user entry in the Password file and gives the control to it. This program may be a word processing software or a spreadsheet program, but generally known as the shell program. It is assumed that there are four users already log in into the system. Among these four users, there are two Bourne Shells, one uses the Korn Shell, and has a spreadsheet program. Every user gets a copy of the shell to serve its request, but only one in the kernel. Using Shell does not hinder the user using spreadsheets or other programs, those programs are running under the active shell. Shell is a single user-specific program that provides an interface between the user and the UNIX kernel. You don't have to use the shell to access UNIX. In the above example, a user replaced the shell using a spreadsheet. When this user logs in, the spreadsheet program starts. When it exits the spreadsheet program, he exited the system. This technology is useful when emphasizing security or hoping that users are shielded with any UNIX interface. Disadvantages is that users cannot use Mail or other UNIX features. Because Login can perform any program - SHELL is just a simple program - you may write your own shell. In fact, three independent development shells have become part of UNIX standards.
They are: Bourne Shell, developed by Stephen Bourne, developing C shell by David Korn, develop shell's diversity of shell to make you choose the most suitable for you or you feel closest. Shell's feature However, which standard shell you choose does not have a lot of relationships, because three shells have the same purpose: provide an interface for users under UNIX. In order to achieve this goal, three shells provide the same basic function: command line interpretation function startup program input / output redirect pipe connection file name replacement variable maintenance environment Control SHELL programming line explanation When you log in, start a interactive When you have shells, you will see a shell prompt, usually the form of $,% or # symbols. When you knock in a row of characters at the prompt, the shell tries to explain it. The input under the shell prompt is sometimes referred to as a command line. The basic format of the command line is the Command Arguments command name parameter (one or more)) Command is the executable UNIX command, the program, utility, or shell program. Arguments is passed to the executor. Most UNIX utilities require the following format: Option FileNames Options file name (one or more)), an example, $ ls -l file1 file2 in the command line There are three parameters in this command line to pass to Ls, the first is an option, and the remaining two is the file name. One of the things that shell makes the kernel is to reduce unwanted information. For computer, blank (Whit-espace) is a class of useless information; therefore, it is necessary to know what shell has done when you encounter a blank. Blank consists of spaces, horizontal tabs, and liftrs. Consider this example: $ Echo Part A Part B Part C Part A Part B PART C This explained that the command line is the echo command with six parameters and delete the blank between the parameters. Suppose if you are printing the header wants to keep blanks, you have to enclose the data using quotation numbers as shown below: $ Echo Part A Part B PART C Part A Part B PART C Single quote Block SHELL from checking quotes. Now shell interprets this line as an echo command with a parameter, and this parameter is exactly the blank string. Startup program When the shell explains the command line, it launches the program required by the command line. Actually, the kernel is executed. In order to start the program, SHELL searches executables in the directory specified by the PATH environment variable. When it finds this file, start a child shell to run the program. You should know that the SHELL does not have to affect its father's environmental settings to establish and manipulate your own environment. For example, a child shell can change its working directory. After it is running, its parent shell's working directory remains unchanged. The input and output redirects will redirect before executing the program. Consider the following examples, where WC Word Statistics Tool Statistics There are five lines of data files: $ WC -L FIVELINES 5 FIVELINES $ WC -L 5 There is a little bit difference. In the first example, the WC knows that it should go out to find a file called FiveLines and operate it. Because the WC knows the file name, it displays it to the user. In the second example, the WC only sees the data without knowing that these data is from there, because the shell is positioned and redirected to the WC's work, and the WC cannot display the file name.
The pipe connection conduit is a special example of the input and output redirection. It connects the output of a command to the input of another command, so the pipe is also established before the calling program. Consider the following command line: $ WHO | WC -L 5 Shell does not display the output of the WHO to the screen, but is directed to the WC input. The file name replaces the shell's responsibility for the file name. The shell is replaced before the program is executed. For example: $ echo * file1 file2 file3 file3x file4, the asterisk is extended to five file names and passed to the ECHO as five parameters. If you want to show an asterisk, you should use quotation marks to enclose it. Variable Maintenance Shell has the ability to perform variable maintenance. Variables are locations that store data as future use. Use the equal sign (=) to assign the variable. $ LOOKUP = / usr / mydir here, shell builds a lookup variable and assigns / usr / mydir to it. Later, you can use the variable value by adding $ symbols before the variable name is added to the command line. Consider these examples: $ Echo $ Lookup / USR / MyDir $ Echo Lookup Lookup C-shell Users should pay attention to the assignment in the c-shell is different from Bourne and Korn shell. C-shell uses the set command to assign a value. $ set look = / usr / mydir pays attention to the equivalence on both sides. Like the file name replacement, the displacement of the variable name is also performed before the calling program. The second example omits the $ symbol. Therefore, the shell simply passes the string to the ECHO as a parameter. In variable replacement, the value of the variable replaces the variable name. For example, in: $ LS $ LOOKUP / FileName Use / USR / MYDIR / FileName to call ls. Environment Control When the Login program is called, the shell sets your environment, including your Home catalog, the terminal type you use, and the path to search for executable files. The environment is stored in an environment variable. For example, you want to change the terminal type, you need to change the value in the TERM variable, as shown below: $ Echo $ TERM VT 100 $ TERM = ANSI $ Echo $ TERM ANSI Note In the C-shell, give environment variables Assign the value using the setENV command. % STENV TERM VT100 Shell Programming You have seen the shell can be used to explain the command line, maintain variables, and execute the program. Also shell is also a programming language. By using process control and conditional judgment to combine commands and variable assignments, you have a powerful programming tool. Using the shell as a programming language, you can automate, write reports, and even you can build and manipulate data files you can build and manipulate your duplicate task. Source: Quote: http://www.linuxeden.com/edu/doctext.php?docid=1337 Single number '' Cancel the special meaning of any characters other than single quotes. Such as: echo 'my name is $ name' The result is: My Name is $ name, and the $ only used as a normal character. Double Quotes "" Cancellation of the special meaning of all characters other than double quotes, $ number and _, is used to specify the input device or file. For example, Mail Root
&& and || Its function is to enable the pipeline. The method is: command1 && command2: When and only when Command1 is successfully executed, it is executed to execute Command2 Command1 || Command2: When and only when Command1 is failed to fail, do not execute command2 1) Why is it called shell? Before you introduce shell, let us re-examine the relationship between users and computer systems: Figure (fixme) We know that the operation of the computer cannot leave the hard body, but the user can't drive directly to the hard body, hard body The driver can only control the management of software called "Operating System", in fact, we talk about Linux every day, strictly just a job system, we call "Kernel". However, from the user's point of view, the user can't operate Kernel directly, but through the Kernel's "shell" program, the so-called shell is communicated with the kernel. This is also the image naming relationship of Kernel with the shell. As shown in the figure: Figure (fixme) From a technical point of view, Shell is an interactive interface (interface) of a user and system, mainly to use the system through the command line (Command line) to complete the work. Therefore, the simplest definition of the shell is --- Command Interpreter: * Translate the user's command to the core, * At the same time, translate the core processing to the user. Every time we complete the system login (log in), we get an interactive mode, also known as the Login Shell or Primary Shell. If a processes perspective, we are under the command, both the child stroke generated by the shell. This is like, we temporarily known for on. If it is a SHELL SCRIPT, the command in the script is performed by a child shell (Sub shell) of another non-interactive mode. That is, the primary shell produces the stroke of the Sub Shell, and the Sub Shell produces the strokes of all commands in the Script. (With regard to the itinerary, we have the opportunity to add again.) Here, we must know: Kernel and shell are different two sets of software, and all can be replaced: * Different job systems use different kernel, * and in the same On a kernel, you can also use different shells. In the preset system of Linux, several different shells can usually be found, and it is often listed in the following file: / etc / shells different shells have different functions, and they are different from each other, or " Datong Small.