PATH

From COMP15212 Wiki
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