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 :
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.
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.
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:
Create a new test.sh script with the following: A=1;
Modify its executable permissions: chmod +x test.sh;
After running SH test.sh, the Echo $A is displayed as empty because a=1 is not passed back to the current shell;
Run. After/test.sh, it is the same effect;
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