PATH: Difference between revisions

From COMP15212 Wiki
gravatar Yuron [userbureaucratinterface-adminsysopPHRhYmxlIGNsYXNzPSJ0d3BvcHVwIj48dHI+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.}}<!--
-->{{Path|User|5}}<!--
-->{{#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 VariablesShellConcepts

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.



Articles on Concepts
About this resource • Application Binary Interface (ABI) • Arrays • Atomicity • Boot • Cache • Cacheability • Caching • Concepts • Containers • Context • Context Switching • Deadlock • Direct Memory Access (DMA) • Environment Variables • Exceptions • File Attributes • Fragmentation • Hypervisor • Interrupts • Operation Ordering • PATH • Pointers • Process Scheduling • Processes • Processor Privilege • Queues • Real Time • Reentrancy • Relocatable Code • Spooling and Buffering • Synchronisation • Thrashing • Threads • Virtual Memory • Virtualisation
Articles on User
"Everything is a File" • Application Binary Interface (ABI) • Arrays • Boot • Buffer Overflow • Containers • Daemons • Disk Partition • Dynamic Memory Allocation • Emulator traps • Environment Variables • Errors • Exceptions • File Attributes • File Locking • File Permissions • Introduction to Operating Systems • Journalling File System • Links • Locks • Man(ual pages in Unix) • Memory Mapped Files • Monitoring • Network File System (NFS) • PATH • Pipes • Pointers • Relocatable Code • Reset • SETUID • Shell • Sockets • Spooling and Buffering • Streams • Structures • Superuser • System Calls • Unix Signals • User • Using Peripherals