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.






Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA