How Linux Shell Works

Source: Internet
Author: User

The most important system program that Linux systems provide to users is the shell command language interpreter. It is not part of the kernel, but is run as a user state outside the core.
Its basic function is to interpret and execute various commands that the user has entered, and to implement the interface between the user and the Linux core. After the initial start of the system, the core establishes a process for each end user to
(1) read the command line entered by the user by the keyboard. (2) analyze the command, take the command name as the file name, and transform the other parameters into the form required by the system call EXECVE () internal processing. (3) The terminal process calls fork () to establish a child process. (4) The terminal process itself uses the system call WAIT4 () to wait for the child process to complete (not wait if it is a background command). When the child process is run, call Execve (), and the child process looks for the file (which is a file of the command interpreter) to the directory based on the file name (i.e., the command name), and calls it into memory to execute the program (explaining the command). (5) If there is A & (background command symbol) at the end of the command, the terminal process does not have to wait for the system call WAIT4 (), immediately sends the prompt, lets the user enter the next command, and goes to ⑴. If there is no & at the end of the command, the terminal process waits until the child process (that is, the process running the command) finishes processing, reports to the parent process (the terminal process), and when the terminal process wakes up, after making the necessary discrimination, the terminal process prompts the user to enter a new command , repeat the above process. 
The shell of the Linux system is the shell of the operating system, providing the user with an interface to use the operating system. It is the general designation of command Language, command interpreter and programming language. The shell is the interface between the user and the Linux kernel, and if you think of the Linux kernel as the center of a sphere, the shell is around the outer layer of the kernel.
When a command is passed to Linux from a shell or other program, the kernel responds accordingly. The shell is a command language interpreter with its own built-in shell command set, and the shell can be called by other applications in the system.
Commands entered by the user at the prompt are interpreted by the shell before being passed to the Linux kernel. Some commands, such as changing the Working Directory command CD, are included inside the shell. There are also commands, such as the Copy command CP and the move command RM,
is a separate program that exists in a directory in the file system. For users, there is no need to care whether a command is built inside the shell or a separate program. The shell first checks whether the command is an internal command, or if it is not an application (the application here can be a utility for Linux itself.
such as LS and RM, can also be purchased commercial programs, such as XV, or free software such as Emacs. The shell then looks for these applications in the search path.
(The search path is a list of directories that can find executable programs.) If the command you typed is not an internal command and the executable file is not found in the path,
An error message will be displayed. If a command can be successfully found, the internal command or application is decomposed into a system call and passed to the Linux kernel. Another important feature of the shell is that it is itself an interpreted programming language, and the Shell programming language supports the vast majority of high-level languages to see
Of program elements, such as functions, variables, arrays, and program control structures. The Shell programming language is easy to learn, and any command you can type in the prompt can be placed into a
Executable in the shell program. When a normal user logs on successfully, the system executes a program called the shell. It is the shell process that provides the command line prompt. As the default value
(Turbolinux system default shell is bash), for ordinary users with "$" as a prompt, the super User (root) with "#" as a prompt. Once the shell prompt appears, you can type the command name and the parameters required by the command. The shell executes the commands. If a command takes a long
Time to run, or produce a lot of output on the screen, you can interrupt it by pressing CTRL + C from the keyboard (to abort its execution before the normal end). When the user is ready to end the logon dialog process, you can type the logout command, Exit command, or file Terminator (EOF) (implemented by Ctrl+d) to end the login.

How Linux Shell Works

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.