Linux系统exec命令(国外英文资料)
Linux系统exec命令(国外英文资料)
Shell's built-in exec command will not start a new shell, but with the command to be executed by the shell to replace the current process, and will clean up the environment of the old process, and other orders will be executed no longer after the exec command.
So, if you are in a shell, an exec ls, then, after the lists the current directory, the himself out of the shell, because the process of the shell has been replaced with the implementation of the ls command only one process, perform over nature also dropped out. To avoid this influence our use, the exec command in a shell script, use the script to invoke this script, call point can use bash a.s h, (a.s h is to store the command scripts), which can build a sub for a.s h shell to carry out, after the execution to exec, the child script process has been replaced by the corresponding exec command.
The source command or ". "will not create a new shell for the script, but simply execute the command that the script contains in the current shell.
Attention should be paid to an exception, however, when the exec command to the file descriptor operation, will not replace the shell, and the operation is done, will continue to follow the orders.
Exec 3 < & 0: the command is to point the operator 3 to the standard input.
In addition, this command can also serve as an option for the find command, as shown below:
(1) in the current directory (including subdirectories), find all TXT files and find the lines that contain the string "bin"
/ -name "*.txt" -exec grep "bin" {} \;
(2) delete all TXT files in the current directory (including subdirectories)
/ -name "*.txt".
To summarize a table:
Exec command action
Exec ls executes ls in the shell and does not return to the original shell after ls
Exec < file as the standard input for exec
Exec > file writes the contents of the file as standard
Exec 3 < file reads the file into fd3
The content read in sort < &3 fd3 is classified
Exec 4 > file will be written to