What is shell?

Source: Internet
Author: User
What is shell introduces how you can do many things without having to know how they actually work. For example, you don't have to understand the physical principle of engine combustion before you can start a car. Lack of electronic knowledge will not prevent you from using cdnserver to listen to music. I don't know what Shell is and how it works. you can still use... what is shell to introduce how you can do many things without having to know how they actually work. For example, you don't have to understand the physical principle of engine combustion before you can start a car. Lack of electronic knowledge will not prevent you from using cdnserver to listen to music. I don't know what Shell is and how it works. you can still use UNIX. However, you can make better use of UNIX. A unix system has three representative shells available: Bourne Shell, Korn shell, and C shells. They will be discussed in Chapter 11, 12, and 13. In this chapter, you will learn: what is Shell that can be used for you? what is the relationship between Shell and the entire system? kernel and Shell nut Shell protect its internal core, the same UNIX shell provides a protection layer for peripherals. When you start a UNIX-based computer, UNIX programs are transferred to the computer's memory until you shut down. This program is called the kernel, which executes a lot of bottom-level and system-level work. The kernel has the responsibility to explain basic commands and send them to the processor. The kernel is also responsible for running and scheduling processes and executing all input and output. The kernel is the heart of a UNIX system, and there is only one kernel. You may be confused about the key responsibilities of the kernel, and kernel commands are equally complex and highly technical. To shield users from the complexity of the kernel, and to protect the kernel from damage caused by misoperations, a shell is built around the kernel ). The user sends a request to the shell. The shell interprets the request and sends the request to the kernel. The rest of this section explains how the outer layer is created. Once the kernel is transferred to the memory, it is ready to execute the user's request. However, the user must first connect to log on and then send a request. No matter what the user logs on, the kernel must know who the user is and how to talk to him. To do this, the kernel calls two special programs, getty and login. correspond to each user's logon point-usually known as a tty-the kernel calls the getty program. This process is called spawning ). Getty displays a logon prompt, and then constantly monitors the call point and waits for the user name input. When getty gets any input, it calls the login program. Login establishes a user's identity and verifies his or her login right. The login program checks the password file. If the password entered by the user is incorrect, the control will return to getty from the logon point. If it is correct, login calls the program recorded in the user entry in the password file and gives control to it. This program may be a word processing software or spreadsheet program, but it is generally called a shell program. Assume that four users have logged on to the system. Two of the four users are using the Bourne shell, one is using the Korn shell, and the other is using the spreadsheet program. Every user gets a copy of the shell to serve its request, but the kernel has only one. Using shell does not prevent users from using workbooks or other programs, but those programs run under the active shell. Shell is a single user-specific program that provides a interface between the user and the UNIX kernel. You do not have to use shell to access UNIX. In the preceding example, a user replaced shell with a workbook. When the user logs in, the workbook program starts. When it exits the spreadsheet program, it exits the system. This technology is useful when you emphasize security or want to block users from any UNIX interface. The disadvantage is that users cannot use mail or other UNIX functions. Because login can execute any program-shell is just a simple program-you may write your own shell. In fact, the three independently developed shells have become part of the UNIX standard. They are: Bourne shell, developed by Stephen Bourne Korn shell, developed by David Korn C shell, the diversity of shell developed by Bill Joy allows you to choose the interface that best suits you or feels closest to you. The shell function does not have much to do with which standard shell you choose, because the three shells share the same purpose: to provide users with an interface in UNIX. To achieve this goal, all three shells provide the same basic functions: command line Interpretation function enable program input and output redirection pipeline connection file name replacement variable maintenance environment control shell programming command line explanation when you log in, start an interactive shell, you will see a shell prompt, usually in the form of $, %, or # symbol. After you type a line in the prompt, shell tries to explain it. Input at a shell prompt is sometimes called a command line. The basic format of a command line is command arguments command name parameter (one or more). command (command) is an executable UNIX command, program, utility, or shell program. Arguments (parameter) is passed to the execution program. Most UNIX applications require the following format for parameters: option filenames option file name (one or more). For example, $ ls-l file1 file2 in the command line has three parameters passed to ls, the first is an option, and the remaining two are file names. One of the things shell does for the kernel is to reduce unnecessary information. For computing machines, the blank space (whit-espace) is a type of useless information. Therefore, it is necessary to know what shell has done when it encounters a blank space. Blank spaces are composed of spaces, horizontal tabs, and line breaks. Consider this example: $ echo part A part B part C here the command line is interpreted as an echo command with six parameters and the blank space between parameters is deleted. If you are printing a report header and want to keep it blank, enclose the data in quotation marks, as shown below: $ echo part A part B part C single quotes prevent shell from checking the quotation marks. Now shell interprets this line as an echo command with a parameter, and this parameter exactly contains a blank string. Start the program after the shell explains the command line, it starts the program required by the command line. The kernel actually runs this program. To start program execution, shell searches for executable files in the directory specified by the PATH environment variable. When it finds the file, it starts a sub-shell to run the program. You should know that the sub-shell does not have to affect its father's environment settings to establish and manipulate its own environment. For example, a shell can change its working directory. after running the shell, the working directory of its parent shell remains unchanged. Input and output redirection shell redirects before executing the program. Consider the following two examples. the wc word statistical tool is used to collect data files with five elements: $ wc-l fivelines 5 fivelines $ wc-l 5, which has a slight difference. In the first example, wc knows that it should go out to find and operate a file named fivelines. Because wc knows the file name, it displays it to the user. In the second example, wc only sees the data and does not know where the data comes from. because shell does the job of locating and redirecting the data to wc, wc cannot display the file name. The pipeline is a special case of input/output redirection. it connects the output of one command directly to the input of another command. Therefore, the pipeline was created before the program was called. Consider the following command line: $ who | wc-l 5 shell does not display the who output to the screen, but directs to the wc input. Shell has the responsibility to replace the file name. Shell is replaced before executing the program. For example, $ echo * file1 file2 file3 file3x file4 here, the asterisk is extended into five file names and passed to echo as five parameters. To display an asterisk, enclose it in quotation marks. Variable maintenance shell is capable of variable maintenance. Variables are the places where data is stored for future use. You can assign values to variables with equal signs (=. $ LOOKUP =/usr/mydir here, shell creates a LOOKUP variable and assigns/usr/mydir to it. Later, you can use the variable value on the command line by adding the $ symbol before the variable name. Consider these examples: $ echo $ LOOKUP/usr/mydir $ echo lookup c-shell users should note that the value assignment in C-shell is different from that in Bourne and Korn shell. C-shell uses the set command to assign values. $ Set LOOKUP =/usr/mydir note that a space is required on both sides of the equal sign. Just like the replacement of file names, the replacement of variable names is performed before the program is called. In the second example, the $ symbol is omitted. Therefore, shell simply passes the string to echo as a parameter. In variable replacement, the variable value replaces the variable name. For example, in $ ls $ LOOKUP/filename, use/usr/mydir/filename as the parameter to call ls. Environment control when the login program calls your shell, the shell sets your environment, including your home directory, the terminal type you are using and the path used to search for executable files. The environment is stored in environment variables. For example, 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 that the setenv command is used to assign values to environment variables in C-shell. % Setenv TERM vt100 shell programming you have seen that shell can be used to explain command lines, maintain variables, and execute programs. In addition, shell is a programming language. By combining commands and variable value assignment using process control and condition judgment, you have a powerful programming tool. Using shell as a programming language, you can automate repeated tasks, write reports, and even create and manipulate your own data files.
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.