Handbook:Parts/Working/EnvVar/ru

Введение
Переменная среда это именованные объекты, который содержит определения, используемые одним или несколькими приложениями. Многие пользователи (особенно новички в Linux) найдут это странным или неуправляемым. Тем не менее, это ошибка: используя переменные среды, можно очень легко изменить настройки для одного или нескольких приложений.

Наиболее важные переменные
В следующей таблице перечислен ряд переменных, используемых в системе Linux и описывает их использование. Примеры их значений приведены после таблицы.

Ниже приведен пример содержащий все эти переменные:

Каталог env.d
Для централизации определения переменных в Gentoo ввели каталог. Внутри каталога есть несколько файлов, такие как, , и т.д., которые содержат переменные, необходимые программе из названия файла.

Например, когда установлен, ebuild создает файл с названием , который содержит определения следующих переменных:

Other distributions might tell their users to change or add such environment variable definitions in or other locations. Gentoo on the other hand makes it easy for the user (and for Portage) to maintain and manage the environment variables without having to pay attention to the numerous files that can contain environment variables.

Например, когда обновляется, также обновляется и файл без малейшего участия пользователя.

This not only benefits Portage, but also the user. Occasionally users might be asked to set a certain environment variable system-wide. As an example we take the http_proxy variable. Instead of messing about with, users can now just create a file (say ) and enter the definition(s) in it:

By using the same file for all self-managed variables, users have a quick overview on the variables they have defined themselves.

env-update
Several files in define the PATH variable. This is not a mistake: when is executed, it will append the several definitions before it updates the environment variables, thereby making it easy for packages (or users) to add their own environment variable settings without interfering with the already existing values.

The script will append the values in the alphabetical order of the  files. The file names must begin with two decimal digits.

The concatenation of variables does not always happen, only with the following variables: ADA_INCLUDE_PATH, ADA_OBJECTS_PATH , CLASSPATH , KDEDIRS , PATH , LDPATH , MANPATH , INFODIR , INFOPATH , ROOTPATH , CONFIG_PROTECT , CONFIG_PROTECT_MASK , PRELINK_PATH , PRELINK_PATH_MASK , PKG_CONFIG_PATH , and PYTHONPATH. For all other variables the latest defined value (in alphabetical order of the files in ) is used.

It is possible to add more variables into this list of concatenate-variables by adding the variable name to either COLON_SEPARATED or SPACE_SEPARATED variables (also inside an file).

When executing, the script will create all environment variables and place them in (which is used by ). It will also extract the information from the LDPATH variable and use that to create. After this, it will run to recreate the  file used by the dynamical linker.

To notice the effect of immediately after running it, execute the following command to update the environment. Users who have installed Gentoo themselves will probably remember this from the installation instructions:

User specific
It might not be necessary to define an environment variable globally. For instance, one might want to add and the current working directory (the directory the user is in) to the PATH variable but do not want all other users on the system to have that in their PATH too. To define an environment variable locally, use or :

After logout/login, the PATH variable will be updated.

Session specific
Sometimes even stricter definitions are requested. For instance, a user might want to be able to use binaries from a temporary directory created without using the path to the binaries themselves or editing for the short time necessary.

In this case, just define the PATH variable in the current session by using the command. As long as the user does not log out, the PATH variable will be using the temporary settings.