The built-in shell exec of the Linuxexec command 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, in addition, other commands after the exec command will not be executed. Therefore, if you are in a shell, execute e...
The built-in shell exec command of the Linux exec command does not start a new shell, but replaces the current shell process with the command to be executed and cleans up the environment of the old process, in addition, other commands after the exec command will not be executed. Therefore, if you execute exec ls in a shell, the shell will exit after the current directory is listed, because the shell process has been replaced by a process that only executes the ls command, the execution will naturally exit after the execution ends. To avoid this impact, we usually place the exec command in a shell script, use the main script to call this script, and use bash. sh, (. sh is the script used to store the command. sh creates a sub shell for execution. after exec is executed, the sub-script process is replaced with the corresponding exec command. The www.2cto.com 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, pay attention to one exception. 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: this command points operator 3 to the standard input. In addition, this command can also be used 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 containing the string "bin. /-name "*. txt "-exec grep" bin "{}/; (2) delete all txt files find in the current directory (including subdirectories. /-name "*. txt "-exec rm {}/;
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