PATH
Depends on | Environment Variables • Shell • Concepts |
---|
Several operating systems include the principle of a search path to look for commands. “Commands” are often (maybe even “usually” in many operating systems) executable files which need to be located, loaded and executed.
A $PATH
in Unix, %PATH%
in Windows is a list of directories which are searched, in order, when a command like my_prog
is executed. The first encountered match will be selected; a mismatch in every
possible place will generate an error.
A path search is only performed if the command does not explicitly specify the path, as in cases such as ./my_prog
or /home/joe/bin/my_prog
.
In Unix the outcome of a PATH
search can be determined by: which my_prog
without executing the utility. This is useful to check that the expected version of some software is being discovered.
The principle of a search path is not limited to searching for files to execute. Your Unix shells probably has a MANPATH
set for example – which the man
command uses to find appropriate documentation. It is not uncommon to set up a path to find shared libraries etc.
Did you know …
A Unix shell will return the result of a command as an argument for another command by bracketing with `
characters. For example (on the system this was typed, at least) more `which firefox`
will find and dump the appropriate start-up script to the terminal.