Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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

PATH="/Users/nikolajandersen/.apportable/SDK/bin:$PATH"

[[ -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
PATH="/Library/Frameworks/Python.framework/Versions/3.3/bin:${PATH}"
export PATH
export PATH=/usr/local/bin:$PATH
export PATH=/usr/local/bin:$PATH

I'm completely new to this and tried to google my way though this but there are still some questions. The first one is: 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?

Maybe someone could guide me to an easy to understand guide / tutorial / book where I could learn all this?

Update This is the output of echo $PATH

/usr/local/bin:/usr/local/bin:/Library/Frameworks/Python.framework/Versions/3.3/bin:/Users/nikolajandersen/.rvm/gems/ruby-2.0.0-p353/bin:/Users/nikolajandersen/.rvm/gems/ruby-2.0.0-p353@global/bin:/Users/nikolajandersen/.rvm/rubies/ruby-2.0.0-p353/bin:/Users/nikolajandersen/.rvm/bin:/Users/nikolajandersen/.apportable/SDK/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/opt/sm/bin:/opt/sm/pkg/active/bin:/opt/sm/pkg/active/sbin

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.

share|improve this question
2  
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 at 15:36
    
Ok, sorry for the multiple questions and thanks for the answers. –  Linus Jan 26 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 at 15:56
    
@Bananguin in the OP's defense, man bash is 5465 lines long, not the easiest of reads. –  terdon Jan 26 at 16:54

1 Answer 1

up vote 2 down vote accepted

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.

share|improve this answer
    
Thanks for the additional info. I updated my question with the echo $PATH output. It looks a little weird. –  Linus Jan 26 at 16:11

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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