PATH: Difference between revisions
Yuron [PHRhYmxlIGNsYXNzPSJ0d3BvcHVwIj48dHI+PHRkIGNsYXNzPSJ0d3BvcHVwLWVudHJ5dGl0bGUiPkdyb3Vwczo8L3RkPjx0ZD51c2VyPGJyIC8+YnVyZWF1Y3JhdDxiciAvPmludGVyZmFjZS1hZG1pbjxiciAvPnN5c29wPGJyIC8+PC90ZD48L3RyPjwvdGFibGU+] (talk | contribs) m (1 revision imported) |
pc>Yuron No edit summary |
||
Line 1: | Line 1: | ||
{{#set: Priority=2 | Summary=Ordered lists of places to look for something.}}<!-- | {{#set: Priority=2 | Summary=Ordered lists of places to look for something.}}<!-- | ||
-->{{#invoke:Dependencies|add|Environment Variables,4|Shell,3|Concepts,2}} | -->{{#invoke:Dependencies|add|Environment Variables,4|Shell,3|Concepts,2}} | ||
Several operating systems include the principle of a <em>search path</em> to | Several operating systems include the principle of a <em>search path</em> to look for commands. “Commands” are often (maybe even “usually” in many operating systems) executable files which need to be located, loaded and executed. | ||
look for commands. “Commands” are often (maybe even | |||
“usually” in many operating systems) executable files | |||
which need to be located, loaded and executed. | |||
A <code>$PATH</code> in Unix, <code>%PATH%</code> in Windows is a list of directories which | A <code>$PATH</code> in Unix, <code>%PATH%</code> in Windows is a list of directories which are searched, in order, when a command like <code>my_prog</code> is executed. The <em>first</em> encountered match will be selected; a mismatch in every | ||
are searched, in order, when a command like <code>my_prog</code> is executed. | |||
The <em>first</em> encountered match will be selected; a mismatch in every | |||
possible place will generate an error. | possible place will generate an error. | ||
A path search is only performed if the command does not explicitly | A path search is only performed if the command does not explicitly specify the path, as in cases such as <code>./my_prog</code> or <code>/home/joe/bin/my_prog</code>. | ||
specify the path, as in cases such as <code>./my_prog</code> or | |||
<code>/home/joe/bin/my_prog</code>. | |||
In Unix the outcome of a <code>PATH</code> search can be determined by: <code>which my_prog</code> without executing the utility. This is useful to check that | In Unix the outcome of a <code>PATH</code> search can be determined by: <code>which my_prog</code> without executing the utility. This is useful to check that the expected version of some software is being discovered. | ||
the expected version of some software is being discovered. | |||
The <em>principle</em> of a search path is not limited to searching for files | The <em>principle</em> of a search path is not limited to searching for files to execute. Your Unix [[Shell|shells]] probably has a <code>MANPATH</code> set for example – which the [[Man|<code>man</code>]] command uses to find appropriate documentation. It is not uncommon to set up a path to find shared [[libraries]] etc. | ||
to execute. Your Unix [[Shell|shells]] probably has a <code>MANPATH</code> set | |||
for example – which the [[Man|<code>man</code>]] command uses to find appropriate | |||
documentation. It is not uncommon to set up a path to find shared | |||
[[libraries]] etc. | |||
---- | ---- | ||
=== Did you know … === | === Did you know … === | ||
A Unix shell will return the result of a command as an argument for | A Unix shell will return the result of a command as an argument for another command by bracketing with <code>`</code> characters. For example (on the system this was typed, at least) <code>more `which firefox`</code> will find and dump the appropriate start-up script to the terminal. | ||
another command by bracketing with <code>`</code> characters. For example (on the | |||
system this was typed, at least) <code>more | |||
`which firefox`</code> will find and dump the appropriate | |||
start-up script to the terminal. | |||
---- | ---- | ||
{{PageGraph}} | {{PageGraph}} | ||
{{Category|Concepts}} | {{Category|Concepts}} | ||
{{Category|User}} | {{Category|User}} |
Revision as of 15:39, 2 August 2019
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.