knowledge/technology/linux/Environment Variables.md
2023-12-04 11:02:23 +01:00

1.5 KiB

obj arch-wiki wiki
concept https://wiki.archlinux.org/title/environment_variables https://en.wikipedia.org/wiki/Environment_variable

Environment Variables

An environment variable is a named object that contains data used by one or more applications. In simple terms, it is a variable with a name and a value. The value of an environmental variable can for example be the location of all executable files in the file system, the default editor that should be used, or the system locale settings. They can be used in the shell or by applications. For example containers in docker make heavy use of environment variables.

Usage

List all environment variables currently set:

$ printenv

The env utility can be used to run a command under a modified environment. The following example will launch xterm with the environment variable EDITOR set to vim. This will not affect the global environment variable EDITOR.

$ env EDITOR=vim xterm

Environment variables can also be stored in .env files:

VAR=VALUE
PATH=$PATH:$HOME/bin

Common environment variables

  • PATH: PATH contains locations seperated by : where the system will look for commands
  • HOME: The location of the users home directory
  • USER: The username
  • LANG, LC_ALL: The language used
  • SHELL: The shell of the user
  • TZ: Timezone information
  • EDITOR: The user's preferred editor