PATH is an environment variable on Unix-like operating systems, DOS, OS/2, and Microsoft Windows, specifying a set of directories where executable programs are located. In general, each executing process or user session has its own PATH setting.

History

edit

Multics originated the idea of a search path. The early Unix shell only looked for program names in /bin, but by Version 3 Unix the directory was too large and /usr/bin, and a search path, became part of the operating system.[1]

Unix and Unix-like

edit

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 superuser also typically has /sbin and /usr/sbin entries for easily executing system administration commands. The current directory (.) is sometimes included by users as well, allowing programs residing in the current working directory to be executed directly. System administrators as a rule do not include it in $PATH in order to prevent the accidental execution of scripts residing in the current directory, such as may be placed there by a malicious tarbomb. In that case, executing such a program requires specifying an absolute (/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 exec call is made from a program, the system searches through $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 process of the command shell or program that issued the command.

DOS, OS/2, and Windows

edit

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 command window, but rather from a graphical user interface. Some programs may add their directory to the front of the PATH variable's content during installation, to speed up the search process and/or override OS commands. In the DOS era, it was customary to add a PATH {program directory};%PATH% or SET PATH={program directory};%PATH% line to AUTOEXEC.BAT.

When 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 current working directory and then searches the path, examining each directory from left to right, looking for an executable filename that matches the command name given. Executable programs have filename extensions of EXE or COM, and batch scripts have extensions of BAT or CMD. 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.

Security implications

edit

Improper use of the PATH variable can introduce security vulnerabilities. In particular, if a program invokes external commands without specifying absolute paths, it may be susceptible to path hijacking (also known as PATH injection), where an attacker places a malicious executable in a directory that appears earlier in the search path. This can result in unintended or malicious code being executed, especially in programs running with elevated privileges.[6]

References

edit
  1. ^ McIlroy, M. D. (1987). A Research Unix reader: annotated excerpts from the Programmer's Manual, 1971–1986 (PDF) (Technical report). CSTR. Bell Labs. 139.
  2. ^ Open Group Unix Specification, Environment Variables
  3. ^ Open Group Unix Specification, execve() function
  4. ^ Dash exec.c as an example of an implementation of a PATH-string parser
  5. ^ Microsoft.com, PATH command
  6. ^ "CWE-426: Untrusted Search Path". MITRE.

New

📚 Artikel Terkait di Wikipedia

Environment variable

An environment variable is a user-definable value that can affect the way running processes will behave on a computer. Environment variables are part

Command-line interface

other things, this prohibits the user from modifying the PATH environment variable, so that if PATH is set to include only directories that contain only permissible

Rpath

paths in the environment variable LD_LIBRARY_PATH, unless the executable is a setuid/setgid binary, in which case it is ignored. LD_LIBRARY_PATH can be overridden

Plan 9 from Bell Labs

path in the shell. A path environment variable ($path) still exists in the rc shell (the shell mainly used in Plan 9); however, rc's path environment

CURL

C:\Windows\System32 directory C:\Windows directory Directories specified in the PATH environment variable curl will return an error message if the remote server is using

COMSPEC

path of the command-line interpreter. It can also be made by a different company or be a different version. Another use of this environment variable is

Freedesktop.org

are expected to make this directory available in their CLI's PATH environment variable. XDG_DATA_HOME For user application's own data files Default to

Spawn (computing)

does not have a path and is not in the current directory, the PATH environment variable determines which directories to search for the file. The string