Important environment variables#
There are a lot of environment variables set. Some are configuration, others are just informational. All currently set environment variables are listed by printenv
. The following table shows a small excerpt of commonly used variables.
Variable |
Usage |
---|---|
|
A |
|
The preferred (command line) text editor |
|
Path of the current users home directory |
|
The user name of the current user |
|
Preferred language for user interfaces |
|
A catch all setting for locale settings |
|
More fine grained locale settings, e.g. |
|
Internal field separator |
|
Many programs define their own variables, e.g. for |
HOME
and USER
are useful to make shell scripts user agnostic. EDITOR
is consulted by programs which start editors for the user, e.g. git
or visudo
.
LANG
can be changed ad-hoc to read manual pages in an other language. For example LANG=de_DE.UTF8 man bash
shows the manual for bash
in German (if available the system). IFS
defines how certain tools (e.g. read
) split data into individual fields. It often set in an ad-hoc per command fashion or stored and reset after a block of commands.
Many tools, for example git
, read their configuration from files and (with higher precedence) from the environment. This is useful to override settings without touching the configuration files.
Note
A common pitfall is to override PATH
instead of just adding a custom directory.
PATH=/opt/bin # this sets PATH to /opt/bin,
# i.e. removes /usr/bin etc.
PATH="$PATH:/opt/bin" # this extends PATH by /opt/bin
Often it is more desirable to keep the default PATH
and create symbolic links in a location which is already in the PATH
. For example in ~/.local/bin/
:
ln -s /opt/bin/my_prog ~/.local/bin/my_prog