Shell built-in command Exec
Shell's built-in command exec is very interesting. It will not start a new shell, but will replace the current shell process with the command to be executed, and clean up the environment of the old process.
Other commands after the exec command will not be executed. Therefore, if you are in a shell, execute Exec
Ls. Then, when the current directory is listed, the shell exits, because the shell process has been replaced by a process that only executes the LS command, and then naturally exits after the execution ends. Is
To avoid this impact on our use, we usually put the exec command in a shell script, and use the main script to call this script. Bash can be used to call the point.
A. Sh, (A. Sh is the script for storing this command), so that a sub is created for A. Sh.
Shell to execute. After exec is executed, the sub-script process is replaced with the corresponding EXEC command.
The source command or "." does not create a shell for the script, but only executes the commands contained in the script in the current shell. However, the exception is that when the exec command is used to operate the file descriptor, the shell will not be replaced, and after the operation is complete, the following command will continue to be executed. Exec 3 <& 0