PATH (variable)
This article needs additional citations for verification. (August 2014) |
PATH is an
History
/usr/bin
, and a search path, became part of the operating system.[1]Unix and Unix-like
On POSIX and Unix-like operating systems, the $PATH
variable is specified as a list of one or more directory names separated by colon (:
) characters.[2][3]
Directories in the PATH
-string are not meant to be escaped, making it impossible to have directories with :
in their name.[4]
The /bin
, /usr/bin
, and /usr/local/bin
directories are typically included in most users' $PATH
setting (although this varies from implementation to implementation). The
/home/userjoe/bin/script.sh
) or relative path (./script.sh
) on the command line.
When a command name is specified by the user or an
$PATH
, examining each directory from left to right in the list, looking for a filename that matches the command name. Once found, the program is executed as a child processDOS, OS/2, and Windows
On DOS, OS/2, and Windows operating systems, the %PATH%
variable is specified as a list of one or more directory names separated by semicolon (;
) characters.[5]
The Windows system directory (typically C:\WINDOWS\system32
) is typically the first directory in the path, followed by many (but not all) of the directories for installed software packages. Many programs do not appear in the path as they are not designed to be executed from a
PATH {program directory};%PATH%
or SET PATH={program directory};%PATH%
line to AUTOEXEC.BATWhen a command is entered in a command shell or a system call is made by a program to execute a program, the system first searches the
. Other executable filename extensions can be registered with the system as well.Once a matching executable file is found, the system spawns a new process that runs it.
The PATH variable makes it easy to run commonly used programs located in their own folders. If used unwisely, however, the value of the PATH variable can slow down the operating system by searching too many locations, or invalid locations.
Invalid locations can also stop services from running altogether, especially the 'Server' service which is usually a dependency for other services within a Windows Server environment.
References
- McIlroy, M. D. (1987). A Research Unix reader: annotated excerpts from the Programmer's Manual, 1971–1986(PDF) (Technical report). CSTR. Bell Labs. 139.
- ^ Open Group Unix Specification, Environment Variables
- ^ Open Group Unix Specification, execve() function
- ^ Dash exec.c as an example of an implementation of a PATH-string parser
- ^ Microsoft.com, PATH command