~]$ export PATH=/bin
~]$ echo $PATH
/bin
~]$ export PATH=${PATH}:/usr/bin:/usr/sbin
~]$ echo $PATH
/bin:/usr/bin:/usr/sbin
~]$ export PATH=/usr/local/bin
~]$ echo $PATH
/usr/local/bin
Question
Every time I need to add a new PATH
in my bash_profile
I just append it to my old path using something like
PATH=$PATH:.....
Then I export PATH
at the end.
If I wanted to add another path and left out the above and just created a new path, would it reset the path to just this new path?
If I exported the PATH
before the new path would it not even reach the new PATH
?
Solution
OTHER TIPS
If you make an export of the PATH it will live only in the current session. The changes into the bash_profile will be permanent, and take effect after restarting the terminal.
So if you export the PATH with the new content, it doesn't mind what content it has into the bash_profile, because you will overwrite it. But when you restart the session, it will have the content of the bash_profile file.
I hope this answer your question.
you use export
to make a local shell variable global. Meaning, to make a shell variable available across inherited sub shell sessions.
Hence it is enough to export
a shell variable just once. You can alter the values as you wish without export
ing it again.