Sourcing a file in Unix/Linux evaluates the file as a list of commands and executes them in the current context. Most people might have used this technique when updating the configurations for their terminals.
|
|
What is sourcing a file?
As mentioned above, sourcing a file is to execute a file in the current context, making the changes applicable in the current shell itself. Usually, when we execute a script, a new sub-shell is created and the script is executed there. In this sense, any changes made by the script will remain in the child process. It’s possible to pass these changes further to the additional grandchildren spawned by the child process, but nothing can be copied back to the parent process.
Syntax: (.
is a synonym for source
.)
Note:
./script
is not. script
, but. script
is equivalent tosource script
Resource
stackoverflow: How to source file from bash script
stackoverflow: What does ‘source’ do?