Linux Source command

Source: Internet
Author: User

What is the difference between the source filename and the sh filename and./filename execution script?
1. When the shell script has executable permissions, there is no difference between using SH filename and./filename to execute the script:/filename because the current directory is not in path, all "." is used to represent the current directory.
2.sh filename re-establishes a child shell, executes the statement inside the script in the child shell, which inherits the environment variables of the parent shell, but the new, changed variables of the child shell are not brought back to the parent shell unless export is used.
3.source FileName: This command actually simply reads the statements inside the script and executes them sequentially in the current shell, without creating a new child shell. Then all the new and changed statements in the script will be stored in the current shell.


To illustrate:
1. Create a new test.sh script with the content: A=1
2. Then make it executable chmod +x test.sh
3. After running SH test.sh, the Echo $A appears empty because A=1 is not passed back to the current shell
4. Run. After/test.sh, it is the same effect
5. Run source test.sh or. Test.sh, and then Echo $A, it will show 1, indicating that the a=1 variable is in the current shell

Linux Source command

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.