Well, the truth is that you can in your situation omit the export statement. Try it out: Open a subshell (by typing bash
), then set the PATH variable to a different value without exporting it, then open another one (this time by typing bash --norc
, to avoid possible errors from .bashrc due to the changed PATH), and do a echo $PATH
. You will see that the PATH variable has changed even though you had not exported it.
The reason, however, is not that PATH is in any way special (i.e. exported automatically by some internal magic of the bash shell). It is exported, because a variable, which you mark once for exporting, is put into the environment - this is what "exporting" actually means - and hence inherited by all child processes. In the case of PATH, it is very likely that some PATH has been set already in /etc/profile and of course you will find an export PATH
in this file. This file is sourced whenever bash is run as login shell and hence inherited by all other processes spawned from it.
It is stil a good idea to export PATH in your own dot-files, because your bash will then be independent from the environment of the parent process. After all, it is possible to construct an example, where a interactive non-login bash shell is invoked by a process which does not have PATH in its environment.