I am trying to setup Metasploit on osx 10.7, but I need to edit my .bash_profile and I noticed something unusual to me. I have been reading about setting the environment variable on http://linux.die.net. I read the .bash_profile stuff and the section on invocation. But, I don't understand why my .bash_profile file looks like this (these are the only two statements in the file):

PATH=/usr/local/bin:/usr/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin :/usr/X11/bin

PATH=/usr/local/opt/ruby193/bin:/usr/local/bin:/usr/local/sbin:/usr/bin:/bin:/us r/sbin:/sbin:/usr/local/bin:/usr/X11/bin

Why are there two PATH statements?

I don't understand how bash works, so I read a little bit about that, .bash_profile, and setting environment variables in a book by Newham & Rosenblatt called bash.

I think we are programming the shell's setup environment. But, from my programming experience I would think that the 1st PATH statement is just getting overwritten by the 2nd statement. I think the 2nd statement was created when I used an automated installation for ruby. The 2nd statement is the same as the 1st one, but it has the ruby directory at the beginning.

Can I just delete the 1st statement?

  • If they're right after each other in the same way you posted here, then the first one is pointless and you can just comment it out or delete it (it may be preferable to just comment out so you have the presumably older value for reference). If they're not then that may be whoever wrote the script trying to get some kind of particular effect. Even though all the directories in the first one are in the second one (sometimes twice) they're in a different order so there may have been some playing around with precedence. Again, only if they're not straight in a row like in the OP. – Bratchley Jun 23 '13 at 19:59

You are right, the first PATH is overwritten by the second one. You can safely delete the first one since the second defines the same paths.


Or you can add $PATH at the end of the second PATH Like this:

  • Why is this voted down? I need to have two paths sourced at the same time. – Gabriel Fair Oct 27 '17 at 22:32
  • The second path is the same as the first, but with an element added at the start. It makes no sense to add $PATH in the second assignment. – Kusalananda Oct 30 '17 at 7:54
  • Yes it does make sense if the second PATH doesn't include everything in the first one or if you have any other PATH variables added in other files. In my example you are 100% sure that you don't over-write existing PATH. (unless you want to do a diff and delete the redundant values, what @shaddy suggested) – sys0dm1n Oct 30 '17 at 8:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.