Javatpoint Logo
Javatpoint Logo

Shell Scripting Sourcing a file

A file is sourced in two ways. One is either writting as source <fileName> or other is writting as . ./<filename> in the command line. When a file is sourced, the code lines are executed as if they were printed on the command line.

The difference between sourcing and executing a script is that, while executing a script it runs in a new shell whereas while sourcing a script, file will be read and executed in the same shell.

In sourcing, script content is displayed in the same shell but while executing script run in a different shell.

Shell Scripting Sourcing a file 1

Look at the above snapshot, we have sourced the file var with one of the method.

Shell Scripting Sourcing a file 2

Look at the above snapshot, we have sourced the file var with another method.





Please Share

facebook twitter google plus pinterest tumbler

Latest 4 Tutorials