Built-in commands, functions, and external commands in Shell

Source: Internet
Author: User

shell recognition: built-in commands, Shell functions, and external commands:
(1) the built-in command is the command executed by the shell itself.
some commands are built-in because of their necessity. For example, if CD is used to change directories, read will send input data from users (and files) to the shell outside.
another built-in command is used for efficiency. The most typical one is the test command, which is often used in script writing. There are also I/O commands, such as ECHO in printf.
(2) the shell function is a complete set of Programs Code , written in Shell language, they can be referenced as commands.
(3) an external command is a copy of the shell (new process) the basic process of the executed command is as follows:
. create a new process. This process is a copy of the shell.
B. Search for specific commands in the directory listed in the PATH variable in the new process.
/bin:/usr/x11r6/bin:/usr/local/bin is the typical default value of the PATH variable.
when the command name contains a slash (/), the path search step is skipped.
C. Replace the shell program in execution with the new program found in the new process and execute it.
D. After the program is completed, the initial shell reads the next command from the terminal and executes the next command in the script.

use type to check whether the command is a built-in command:
type (without parameters) indicates whether the command is a built-in command or an external command
-T: file external command; alias command alias; builtin built-in command
-A: The command path is displayed.
how to execute the interactive command:
after you enter a command in the command line, the shell usually fork and exec the command, except for the built-in command of the shell, executing the built-in command is equivalent to calling a function in a shell process and does not create a new process.
for example, commands such as CD, alias, umask, and exit are built-in commands. All commands that cannot find the location of the program file by using the which command are built-in commands. the built-in commands do not have a separate man manual. To view the built-in commands in the man manual, Run man bash. -Builtins : although the built-in command does not create a new process, there will also be an exit status. Generally, 0 indicates that the process is successful, and non-zero indicates that the process is failed, although the built-in command does not create a new process, there will be a status code after the execution ends. You can also use the special variable $? Read

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.