Wednesday, December 7, 2016

sourcing vs executing a script

source a script vs executing(or running) a script, what is the difference?

short:
sourcing will run the commands in the current shell process. executing will run the commands in a new shell process.

long:
sourcing :
Sourcing the script does not create a new shell. All commands are run in the current shell and changes to the environment take effect in the current shell.

It's as if you typed the contents of the script.

 running:
The changes were made in a new shell. The current shell spawned a new shell to run the script. The script is running in the new shell and all changes to the environment take effect in the new shell. After the script is done the new shell is destroyed. All changes to the environment in the new shell are destroyed with the new shell. Only the output text is printed in the current shell.




link :
http://superuser.com/questions/176783/what-is-the-difference-between-executing-a-bash-script-and-sourcing-a-bash-scrip

 

No comments:

Post a Comment