How to parse the source command and script under Linux

Source: Internet
Author: User

Linux Source command and Script execution mode parsing http://blog.csdn.net/wangyangkobe/article/details/6595143

When I modify the/etc/profile file, I want it to take effect immediately without having to log in again;Sourcecommands, such as: Source/etc/profile
The source has beenLearning, and compares it with the sh execution script, and now summarizes it.

SOURCE command:
The source command is also known as thePoint Command", or a dot symbol (.), is the internal command of bash.
function: MakeShellReads in the specified shell program file and executes all the statements in the file in turn
The source command is typically used to re-execute the initialization file you just modified to take effect immediately without having to log off and log back on.
Usage:
SOURCE filename or. FileName
The source command (from Shell C) is the built-in command of the bash shell, and the Point Command (.), which is a dot symbol (from the Bourne Shell), is another name for source.

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 newTest. sh script, 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

How to parse the source command and script under Linux

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.