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

PATH

A : separated list of path to look for executables

EDITOR

The preferred (command line) text editor

HOME

Path of the current users home directory

USER

The user name of the current user

LANG

Preferred language for user interfaces

LC_ALL

A catch all setting for locale settings

LC_*

More fine grained locale settings, e.g. LC_COLLATE, …

IFS

Internal field separator

GIT_*

Many programs define their own variables, e.g. for git: GIT_AUTHOR, …

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