Introduction to shell built-in command Exec

Source: Internet
Author: User

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
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.