Unix PATH Variable
All the UNIX shells use a variable called PATH
[[The PATH versus the path]].
This variable contains a list of directories that the shell will search when you type in a command.
When you type in the
command, the shell searches all the directories listed in your PATH until it finds a file named ls.
It goes through each of the directories, in the order listed in the PATH, searching for your program.
So, does it basically mean the location?
Inserting sidebar here
The command below assigns a new value to the PATH variable. Colons are used to separate the directory names in the PATH.
This PATH contains two directories, /usr/bin and . (the current directory.)
script names and the PATH
When two programs have identical names, your PATH determines which one will run when you run the command.
For example, if you have an
ls command stored in the /usr/bin directory and another version of ls stored in the
/tmp directory you might run either version when you type in
If /tmp is listed first in your PATH, then
/tmp/ls will run. If /usr/bin is listed first in your PATH, then
/usr/bin/ls will run.
When naming your scripts, you should choose a name that is not identical to a UNIX command.
Usually the shell will locate the directory for the UNIX command in your PATH before the directory for your script.
This means that the UNIX command will run instead of your script when you type in the identical name on the command line
Do not name your script test or script.
These are both the names of UNIX commands. When you attempt to run your script, the shell will run these commands instead.
This is because the directories for these commands come first in your PATH, before your current directory.
These file names are tempting; its natural to want to call your script script. Instead, try using related file names like test1 or script2.
The PATH and child shells
When a child process is created, all of the exported variables
changed that from a glossary link to a sidebar link. If it is a glossary term as well,
we should style the next instance of it in this paragraph as a glossary link.But the first instance seems to point to the sidebar, not to the glossary term.
Review of exported variables
The PATH is an exported variable, so any shells you create from your login shell will be sent a copy of your PATH variable.
The PATH and startup files
Your system administrator will probably set an initial PATH for your account by creating a startup file
in your home directory.
The commands in these files are run automatically by UNIX whenever you login to your account.
You can change the value of PATH in your startup file
[[Examples of changing the PATH in a startup file]] .
Path Variable Exercise
Click the exercise link to practice setting the value of PATH and observe how this affects which command is run.
Path Variable Exercise
The next lesson concludes the module.