Describe the 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
script names and the PATH
ls 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.)
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,
/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.
The PATH and child shells
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.
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 and startup files
Is this actually a review or is itnew information? If we make this intomodule 2, then should we assume that people wont know thisyet? If they
wont then maybe we should explain further?
They should know this from part I of the course.
belonging to the parent process are passed down to the child. The PATH is an exported variable, so any shells you create from your login shell
will be sent a copy of your PATH variable.
Path Variable Exercise
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]] .
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.