Gilbert
Gilbert

Reputation: 19

What is the difference between PATH and $PATH in .bash_profile?

The context for the following is that I've been playing with Node.js and npm, and want to make sure they're correctly installed.

I understand .bash_profile is a config file for Bash. And it's where you set your environmental variable PATH. What I'm not clear on is the difference between PATH and $PATH, as in:

export PATH=/usr/local/bin:$PATH

What's the dollar sign doing? Would you help me understand the difference with an example?

Upvotes: 0

Views: 1319

Answers (1)

Ljm Dullaart
Ljm Dullaart

Reputation: 4969

This is very basic BASH stuff. With the $-sign you refer to the content of the variable. An example:

a=text
echo a
echo $a

gives you

a
text

So, in the example above,

PATH=/usr/local/bin:$PATH

will put /usr/local/bin, followed by a colon and then followed by the original content of the PATH-variable in PATH. If you would do

PATH=/usr/local/bin:PATH

the PATH-variable would contain the literal word PATH and not the previous content of the PATH-variable.

You should get some introductory material into the bash, for example at tldp.org.

Upvotes: 3

Related Questions