Environment variables are global system variables accessible by all the processes/users running under the Operating System (OS), such as Windows, macOS and Linux.
Environment variables are useful to store system-wide values, for examples,
PATH
: the most frequently-used environment variable, which stores a list of directories to search for executable programs.OS
: the operating system.COMPUTENAME
, USERNAME
: stores the computer and current user name.SystemRoot
: the system root directory.HOMEDRIVE
, HOMEPATH
: Current user's home directory.When you launch an executable program (with file extension of ".exe
", ".bat
" or ".com
") from the CMD shell, Windows searches for the executable program in the current working directory, followed by all the directories listed in the PATH
environment variable. If the program cannot be found in these directories, you will get the an error.
Most of the Unixes and macOS use the so-called Bash Shell in the "Terminal". When you launch an executable program (with file permission of executable) in a Bash shell, the system searches the program in ALL the directories listed in the PATH
. If the program cannot be found, you will get the an error.
There are some differences among other OS:
.
) before searching the PATH
entries. (Unixes/macOS does not search the current directory, unless you include it in the PATH explicitly.);
) as the path separator; while Unixes/macOS uses colon (:
)._
), e.g., JAVA_HOME
._
), e.g., JAVA_HOME
.Programming languages are divided into groups depending on their characteristics.