Linux Source Command

Source: Internet
Author: User

Linux Source command:

Usual usage: source filepath or. FilePath

Function: Enables the current shell to read into a shell file with a path of FilePath and executes all the statements in the file in turn, typically to re-execute the newly modified initialization file for immediate effect without having to log off and log back on. For example, when we modify the/etc/profile file and want it to take effect immediately without having to log in again, you can use the source command, such as Source/etc/profile.

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. This can be seen from the usage as well.

the difference between source filepath and SH filepath,./filepath :

    1. When the shell script has executable permissions, there is no difference between sh filepath and./filepath:/filepath is because the current directory is not in path, all "." is used to represent the current directory.

    2. SH filepath will re-establish a child shell, executing the statement inside the script in the child shell, which inherits the environment variables of the parent shell, but the child shell is new, and its changed variables are not brought back to the parent shell unless export is used.

    3. SOURCE filename 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 script with the following: A=1;

    2. Modify its executable permissions: chmod +x;

    3. After running SH, the Echo $A is displayed as empty because a=1 is not passed back to the current shell;

    4. Run. After/, it is the same effect;

    5. Run source or., and then Echo $A, it will show 1, indicating that the a=1 variable is in the current shell;

Linux Source Command

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