Shell various ways to perform the difference

Source: Internet
Author: User

Shell scripts are executed in various ways (source./*.sh,. The difference between./*.sh,./*.sh)

Original source: http://blog.csdn.net/dance_rise/article/details/8573560

Conclusion One: The/*.sh is executed in the same way as sh./*.sh or bash./*.sh, the three ways to execute the script are to restart a child shell that executes the script (implemented by fork) in the child shell.

Conclusion two:. Source./*.sh and. The./*.sh is executed in an equivalent manner, either by executing the script in the current shell process, rather than restarting a shell and executing the script in the child shell process.

Validation: Variables that are not exported by export (that is, non-environment variables) cannot be inherited by the shell.

Validation results:

[[Email protected] ~] #name =dangxu//define general variables
[[email protected] ~]# echo ${name}
Dangxu
[[email protected] ~]# cat test.sh//Verify script, instantiate in header./*.sh
#!/bin/sh
Echo ${name}
[[email protected] ~]# ls-l test.sh//Verification script executable
-rwxr-xr-x 1 root root 6 11:09 test.sh
[Email protected] ~]#/test.sh//The following three commands prove the conclusion of a

[Email protected] ~]# sh./test.sh

[[email protected] ~]# bash./test.sh

[Email protected] ~]#. ./test.sh//The following two commands prove the conclusion of two
Dangxu
[[email protected] ~]# source./test.sh
Dangxu

Shell various ways to perform the difference

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.