Unix $PATH Environment Variable

The $PATH environment variable stores a list of directories where shell programs are defined (e.g. cat, echo, cp, mv). When a shell program is run (i.e. $ cat a_file), the program definition is searched for in each of the directories specified in the $PATH environment variable.

Each directory in the $PATH environment variable is separated with a colon (:)

$ echo $PATH
# => /usr/bin:/bin:/usr/sbin

To print each path on a separate line, use the following command:

$ echo $PATH | tr ":" "\n"

To add the ~/Desktop/example/bin directory to $PATH, run the following command:

$ PATH="$PATH:$HOME/Desktop/example/bin"

Recall that $PATH is a list of directories delimited with a colon. In the previous command, the PATH environment variable is reset to the previous value of PATH (i.e. $PATH) followed by the new directory that is being added to PATH. The $HOME environment variable is set to the value of the home directory.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s