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