Three different methods (fork, exec, source) for calling another script in shell scripts)

Source: Internet
Author: User

Fork

Usage: fork/directory/script. Sh

Fork is the most common. It uses/directory/script. Sh directly in the script to call the script. Sh script.

Run a sub-shell script to execute the call. When Sub-shell is executed, parent-shell is still running.

After sub-shell is executed, the system returns parent-shell. Sub-shell to inherit environment variables from parent-shell. However, the environment variables in sub-shell will not be brought back to parent-shell.

Exec

Usage: exec/directory/script. Sh

Unlike fork, exec does not require a new sub-shell to execute the called script. The called script and the parent script are executed in the same shell. However, after exec is used to call a new script, the content after the exec line in the parent script will not be executed again. This is the difference between exec and source.

 

Source

Usage: Source/directory/script. Sh

The difference with fork is that instead of opening a sub-shell to execute the called script, it is executed in the same shell. therefore, the variables and environment variables declared in the called script can be obtained and used in the main script.

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.