I am very new to Linux and I put the following command at the end of the file .profile
under my home folder:
export PATH="~/.composer/vendor/bin:$PATH"
I know the issues of environment variables and their values a bit from Windows, but in this case I want to understand what this command does, and what are the parts that it comprises:
-
What is this "export" phrase at the start? Is it exporting the data to be available for Bash?
-
What is the first
PATH
and what is the second$PATH
, and why do we need two?
Best Answer
export
is a command (more precisely it's a Bash builtin, i.e. it's not an executable present inPATH
, it's a command that Bash has built-in in itself).export
sets the environment variable on the left side of the assignment to the value on the right side of the assignment; such environment variable is visible to the process that sets it and to all the subprocesses spawned in the same environment, i.e. in this case to the Bash instance that sources~/.profile
and to all the subprocesses spawned in the same environment (which may include e.g. also other shells, which will in turn be able to access it).The first
PATH
as explained above is the environment variable to be set usingexport
.Since
PATH
normally contains something when~/.profile
is sourced (by default it contains/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games
), simply settingPATH
to~/.composer/vendor/bin
would makePATH
contain only~/.composer/vendor/bin
.So since references to a variable in a command are replaced with (or "expanded" to) the variable's value by Bash at the time of the command's evaluation,
:$PATH
is put at the end of the value to be assigned toPATH
so thatPATH
ends up containing~/.composer/vendor/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games
(i.e. whatPATH
contains already plus~/.composer/vendor/bin:
at the start).