#1 Add the execution permission chmod U + x a to the script. sh, and then you can directly use the full path to execute the script, for example, in the current folder. /. sh. If the directory where the script is located is in the path environment variable,. sh.ProgramIs a truth)
#2 sh/bash./A. Sh in this case, the script does not need to have execution permissions.
Both of the preceding methods are executed in the sub-shell. That is to say, the current Shell needs to start another shell to execute the commands in A. Sh.
#1 source./A. Sh
#2./A. Sh (note the previous .)
The preceding two execution methods are executed in the current shell and do not need to create a sub-shell.
Source and. Command: used to execute a script
The difference between the first two methods and the last two methods: If you export $ KKK = 111 In a script, if you use. /. SH: run the script. After the script is executed, run echo $ KKK and find that there is no value. If you use source to execute the script and then echo it, you will find that KKK is 111. Because of the call. /. sh to execute shell is run in a sub-shell, so after execution, the structure is not reflected in the parent shell, but the source is different, it is executed in this shell, so you can see the result.
# The script is run in a subshell environment. After the script is executed, the subshell automatically exits.
# The system environment variables in a shell are valid only for the shell or its sub-shell. The variables disappear when the shell ends (and cannot be returned to the parent shell)
# Variables defined with export will be copied to the sub-shell of the shell.
# VARIABLES not defined by export are valid only for this shell and are invalid for the sub-shell.