I'm using a mac for some years now and as I'm currently learning ruby on rails, I felt like I should learn more about the system I'm using. I took a look at the ~/.bash_profile, it looks like this


[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM$

# Setting PATH for Python 3.3
# The orginal version is saved in .bash_profile.pysave
export PATH
export PATH=/usr/local/bin:$PATH
export PATH=/usr/local/bin:$PATH

As there are two identical export PATH=/usr/local/bin:$PATH lines, I tried to delete the one. As a result, commands like nano and ls didn't work anymore. I reverted the change but I don't understand why it has to stated two times.

Another question is: why does it sometimes $PATH and sometimes just PATH without the $? Why does -s "$HOME/.rvm/scripts/rvm" stand in [[ ]] braces? And what does export PATH do?

Update This is the output of echo $PATH


It seems like you were right with the newline. I deleted the line again and made sure that there is a blank line in the end. Now the commands are still working.

  • 3
    Please don't combine multiple questions in a single post. The issue with PATH vs $PATH is explained here, and [[ ]] is a test operator, it basically means if. The duplicate exports should have no effect, that's weird, I recommend you focus on that one and make you question about the export. – terdon Jan 26 '14 at 15:36
  • Ok, sorry for the multiple questions and thanks for the answers. – Niko Jan 26 '14 at 15:43
  • Welcome to the bright side! Before we google, we like to read manuals, called man pages. Bash's man page (man bash) can answer all your questions. – Bananguin Jan 26 '14 at 15:56
  • @Bananguin in the OP's defense, man bash is 5465 lines long, not the easiest of reads. – terdon Jan 26 '14 at 16:54

The PATH before = is a variable name and the combination tells bash to store the stuff behind the = in the variable.
The $PATH is the value of the variable PATH up until then.

The combination PATH="some_path_to_stuff:$PATH" extends the PATH variable. In bash this is a colon (:) separated list.

Regarding the double addition of /usr/local/bin, I can only guess that the second version has no newline after it (and is at the end of the file). In principle this should give you a PATH which starts with /usr/local/bin:/usr/local/bin:..... You can check that with

echo $PATH

And if there is only one time /usr/local/bin then do:

echo "" >> ~/.bash_profile

and login an try to print $PATH again.

  • Thanks for the additional info. I updated my question with the echo $PATH output. It looks a little weird. – Niko Jan 26 '14 at 16:11

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.