$linuxjunkies
>

environment variable

also: env var, shell variable

A named value that the shell and programs use to configure behavior and pass information. Environment variables are inherited by child processes and persist for the duration of a session.

An environment variable is a key-value pair stored in your shell session that programs can read to customize their operation. The shell sets standard variables like PATH (where to find executables) and HOME (your home directory), and you can create your own.

View all variables with env or printenv. Set a temporary variable with export MYVAR=value, which makes it available to child processes. For example: export LANG=en_US.UTF-8 tells programs which language to use.

Persist variables by adding them to shell config files like ~/.bashrc or ~/.zshrc. Access a variable's value in commands using $VARIABLE, like echo $HOME or cd $HOME.

Related terms