The difference between shell source sh bash with the ./

source use

source FileName

Role: reading and FileName in the command is run in the bash environment. The file filename can not "execute permissions"
NOTE: This command is normally used instead of command. "."

source .bash_profile
. .bash_profile
两者等效

source typically used to modify the file you just entered into force

Use the bash and sh

sh FileName
 bash FileName

Role: reading and FileName in the command is run in the bash environment. The file filename can not "execute permissions"
Note: when performing two different files, each with their own shell is used to run the file.

./usage of

Here Insert Picture Description
Role: open a sub-shell to read and execute commands FileName.
Note: launches another command interpreter when you run a shell script.
Note: need to add privileges to execute.

The difference between the source sh bash with ./

The following examples demonstrate the difference between source, sh, bash and the ./:
Conclusion one: the script for execute permission, / .sh, SH ./ .sh and bash ./*.sh same, these three script execution all the way to restart a sub shell, execute this script in sub-shell.

Conclusion 2:. Source * .sh and * .sh means of implementation are equivalent, that is, two execution are ways to do this script in the current shell process, instead of restarting a shell and execute this process in the sub-shell script.
Here Insert Picture Description
Verify basis: variable (ie non-environmental variables) are not export to export is not inherited quilt shell
Here Insert Picture Description

Published 75 original articles · won praise 7 · views 10000 +

Guess you like

Origin blog.csdn.net/zhengdong12345/article/details/103902485