Article title: Linux tutorial-TurboLinuxShell. Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.
Shell is the interface between the user and the Linux operating system. There are multiple shells in Linux, where Bash is used by default. This chapter describes how shell works, shell types, General shell operations, and Bash features.
What is shell?
As the operating system shell, the Linux system shell provides users with the interface to use the operating system. It is a general term for the command language, command interpretation program, and programming language.
Shell is the interface program between the user and the Linux kernel. if you think of the Linux kernel as the center of a sphere, shell is centered around the outer kernel. When commands are passed from shell or other programs to Linux, the kernel will respond accordingly.
Shell is a command language interpreter. it has its own built-in shell command set, and shell can also be called by other applications in the system. The commands entered by the user at the prompt are explained by shell and then passed to the Linux core.
Some commands, such as changing the working directory command cd, are included in the shell. There are also some commands, such as copy command cp and move command rm, which are separate programs in a directory in the file system. For users, there is no need to worry about whether a command is built inside shell or a separate program.
Shell first checks whether the command is an internal command. if it does not check whether it is an application (the application here can be a Linux utility, such as ls and rm, it can also be a purchased commercial program, such as xv, or a free software, such as emacs ). Then shell searches for these applications in the search path (the search path is a list of directories where executable programs can be found ). If the entered command is not an internal command and the executable file is not found in the path, an error message is displayed. If the command is successfully found, the internal command or application will be decomposed into system calls and passed to the Linux kernel. 0-1 demonstrates how the shell executes commands.
User commands
External commands
UNIX core
Working Principle of 0-1 shell
Another important feature of shell is that it is an interpreted programming language. the shell programming language supports most program elements that can be seen in high-level languages, such as functions, variables, arrays, and program control structures. The shell programming language is easy to learn. any command that can be typed in a prompt can be put into an executable shell program.
When a common user successfully logs on, the system executes a program called shell. The shell process provides a command line prompt. As the default value (BASH is the default shell in TurboLinux), "$" is used as a prompt for common users and "#" is used as a prompt for super users (root.
Once a shell prompt appears, you can enter the command name and the parameters required by the command. Shell will execute these commands. If a command takes a long time to run, or a large amount of output is generated on the screen, you can press ctrl + c on the keyboard to interrupt it (stop it before it ends normally ).
When you are about to end the login dialog process, you can enter the logout command, the exit command, or the file terminator (EOF) (press ctrl + d to complete the logon.
Let's take an internship on how shell works.
$ Make work
Make: *** No rule to make target 'work'. Stop.
$
Note: make is the name of a command in the system, followed by the command parameters. After receiving this command, shell will execute it. In this example, the system returns information and stops executing the command because the input command parameters are incorrect.
In the example, shell looks for a program named make and runs it with the work parameter. Make is a program that is often used to compile large programs. it is compiled with parameters as the goal. In "make work", the goal of make compilation is work. Because make cannot find the target named "work", it will give an error message indicating that the operation failed, and the user will return to the system prompt.
In addition, if the shell cannot find the program named by the command name after you type the command line, an error message is displayed. For example, if you type:
$ Myprog
Bash: myprog: command not found
$
You can see that the user gets an error message that does not find the command. After the user knocks on the wrong command, the system generally gives such an error message.
Shell type
There are multiple types of shell in Linux, the most common of which are Bourne shell (sh), C shell (csh), and Korn shell (ksh ). Each of the three shells has its own advantages and disadvantages. The Bourne shell is the original shell used by UNIX and can be used on every UNIX. Bourne shell is excellent in shell programming, but it is inferior to several other shells in dealing with user interactions. The default shell in Linux is the Bourne Again shell, which is an extension of the Bourne shell, Bash for short. it is completely backward compatible with the Bourne shell, in addition, many features are added and enhanced based on the Bourne shell. Bash is placed in/bin/bash. it has many features, such as command completion, command editing, and command history table, it also contains many advantages of C shell and Korn shell, flexible and powerful programming interfaces, and friendly user interfaces.
C shell is a shell that is more suitable for programming than the Bourne shell. Its syntax is similar to that of C. Linux provides Tcsh for people who like to use C shell. Tcsh is an extension of C shell. Tcsh includes command line editing, programmable word completion, spelling correction, historical command replacement, job control, and syntax similar to C language. it is not only compatible with Bash shell as a prompt, it also provides more prompt parameters than Bash shell.
The Korn shell combines the advantages of C shell and Bourne shell and is fully compatible with the Bourne shell. Linux provides pdksh (ksh extension), which supports task control and can be suspended on the command line, executed in the background, awakened, or terminated.
Linux does not neglect other shell users, but also includes some popular shell such as ash and zsh. Each shell has its purpose. some shells have patents, and some can be obtained from the Internet or other sources. To decide which shell to use, read the online help of various shells and try it out.
When you log on to Linux, the/etc/passwd file determines the shell to use. For example:
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