Skip to content
Search

Environment variable

lastmod 2025-10-15created 2018-07-1917 edits

An environment variable is a dynamic-named value that can affect the way running processes will behave on a computer.

They are part of the environment in which a process runs. For example, a running process can query the value of the TEMP environment variable to discover a suitable location to store temporary files, or the HOME or USERPROFILE variable to find the directory structure owned by the user running the process.

They were introduced in their modern form in 1979 with Version 7 Unix, so are included in all Unix operating system flavors and variants from that point onward including Linux and macOS. From PC DOS 2.0 in 1982, all succeeding Microsoft operating systems including Microsoft Windows, and OS/2 also have included them as a feature, although with somewhat different syntax, usage and standard variable names.

An environment variable is a set of dynamic values that affect the way processes behave on a computer.

Categories

Softwares

  • Infisical - Open source for encrypting environment variables and sharing them with your team

Common

PATH

Contains a colon-separated list of directories that the shell searches for commands whose names do not contain a slash. Equivalent to the %PATH% variable in DOS, OS/2, and Windows.

HOME

Contains the location of the user's home directory. The current user's home directory can be found through C functions such as getpwuid and getuid, but $HOME is often used for convenience in various shell scripts (and other contexts).

DISPLAY

This variable is used to indicate to graphical applications where to display the actual graphical user interface, the value consists of 3 parts: A host-name followed by a colon (:), a display number followed by a dot (.) and a screen number. The host-name part can be used to have the graphical output sent to a remote machine over the network. It can be omitted when the output is meant for an X server running on the local machine. The display number allows selecting among multiple X servers running on the same machine (Ubuntu uses multiple X servers to enable multiple graphical desktop sessions). Although the screen number is used to select among multiple physical screen that are managed by the same X server, it is rarely set to anything other than "0" nowadays. Manually setting the "DISPLAY" environment variable's value is rarely needed nowadays since it can be automatically and intelligently adjusted by many applications such as "GDM" and "SSH" when needed.

Contains the display identifier that X1 programs use by default.

Example:

:0.0
localhost:10.0
terminal01:0.0

Unix

$PWD
Points to the current directory. Same as the output of the pwd command when called without variables.
$LD_LIBRARY_PATH
On many Unix systems with a dynamic linker, contains a colon-separated list of directories that the dynamic linker searches for shared objects when building a process image after exec, before searching any other directories.
$LANG, $LC_ALL, $LC_...
$LANG is used to set the default locale. For example, if the locale value is pt_BR, the language is set to (Brazilian) Portuguese.
Different aspects of localization are controlled by individual $LC_- variables ($LC_CTYPE, $LC_COLLATE, $LC_DATE, etc.).
$LC_ALL can be used to force the same locale for all aspects.
$TZ
Refers to the time zone. It can be used in several formats, either by specifying the time zone itself or by referring to a file (in /usr/share/zoneinfo).

Other

  • TMOUT - Time to keep a user account's Login Session (unit: seconds)
  • HISTTIMEFORMAT - A predefined environment variable for the time value of the history command. (e.g. "[%Y/%m/%d %H:%M] ")

Windows

  • %ALLUSERSPROFILE%
  • %APPDATA%
  • %COMPUTERNAME%
  • %COMSPEC% - C:\Windows\System32\cmd.exe
  • %HOMEDRIVE% - C:
  • %HOMEPATH%
  • %PATH%
  • %PATHEXT%
  • %PROGRAMFILES%
  • %PROMPT%
  • %SYSTEMDRIVE%
  • %SYSTEMROOT%
  • %TEMP% and %TMP%
  • %USERNAME%
  • %USERPROFILE%
  • %WINDIR%

Well-known

Favorite site

author Zer0 sitemap