Monday, October 3, 2011

The 'source' command

The source command allows us to run a file in the current shell, such that if that file creates any changes in the environment, then the changes are not after the process exits.

Normally when we run an executable file, it is run in a sub-shell. Because of this any changes to the environment are lost when the process exits. However, let's say we make some changes to .bashrc and we want to changes to be reflected in the current shell. We cannot just run .bashrc, because the new changes will be lost the moment the process exists.\

However, if we run source ~/.bashrc then the changes will persist in the current shell's environment.

I believe there is one more way to do this
. runshellfile
Notice the space after the . This causes the environment changes to persist in the current shell.