Reads and executes commands from the specified file in the current shell environment.
source filename [arguments]
filename: file to be executed
arguments (optional): parameters passed to the file
source returns the return value of the last command in the file. It will fail if the file cannot be read.
[root@localhost ~]# source ~/.bash_profile
Q: What is the difference between source
and sh
in executing files?
A: sh
is executed in a subshell. source
will cause the variables and functions of the executed file to be loaded into the current terminal environment (excluding variables modified by local in the function, etc.); it is recommended that you refer to the export
command. Knowledge Points Section