环境变量

https://wiki.archlinux.org/index.php/Environment_variables

1. 实用工具
列出具有值的当前环境变量

$ printenv

使用ENV实用程序可用于将修改后的环境下运行的命令。
以下示例将启动xterm并将环境变量EDITOR设置为vim。这不会影响全局环境变量EDITOR。
$ env EDITOR = vim xterm

3. 定义变量
3.1 全局Globally 

大多数Linux发行版都会告诉您在/etc/profile其他位置更改或添加环境变量定义。
请记住,还有特定于包的配置文件包含变量设置,例如/etc/locale.conf。
确保维护和管理环境变量,并注意可以包含环境变量的众多文件。
原则上,任何shell脚本都可用于初始化环境变量,但遵循传统的UNIX约定,这些语句应仅存在于某些特定文件中。
下列文件应使用你的系统上定义全局环境变量:/etc/environment,/etc/profile和外壳特定的配置文件。

/etc/environment由pam_env模块使用,并且与shell无关,因此无法使用脚本或glob扩展。该文件只接受variable=value对。有关详细信息,请参阅pam_env(8)和pam_env.conf(5)。
shell的全局配置文件,初始化变量并运行脚本。例如Bash#配置文件或Zsh#启动/关闭文件。
/etc/profile仅为登录shell初始化变量。但是,它确实运行脚本,并且可以被所有与Bourne shell兼容的shell使用。

3.2 每位用户Per user 

注意: dbus守护程序和systemd的用户实例不会继承在类似~/.bashrc等位置设置的任何环境变量。
这意味着,例如,dbus激活的程序(如Gnome Files)默认情况下不会使用它们。请参阅Systemd/User#Environment_variables。
https://wiki.archlinux.org/index.php/Systemd/User#Environment_variables

您并不总是希望全局定义环境变量。例如,您可能希望添加/home/my_user/bin到PATH变量但不希望系统中的所有其他用户PATH也在其中。可以在许多不同的文件中定义本地环境变量:

~/.pam_environment是pam_env模块使用的/etc/security/pam_env.conf [1]的用户特定等价物。有关详细信息,请参阅pam_env(8)和pam_env.conf(5)。
shell的用户配置文件,例如Bash#配置文件或Zsh#启动/关闭文件。
~/.profile被许多shell用作后备,请参阅wikipedia:Unix shell#配置文件。
systemd将加载环境变量,~/.config/environment.d/*.conf参见environment.d(5)和https://wiki.gnome.org/Initiatives/Wayland/SessionStart。
要将目录添加到PATH本地用法,请将以下内容放入~/.bash_profile:
$ export PATH="${PATH}:/home/my_user/bin"
更新变量,重新登录或源文件:$ source ~/.bash_profile。

3.3 Per session
只要您不注销,该PATH变量将使用临时设置。
$ export PATH="${PATH}:/home/my_user/tmp/usr/bin"

https://wiki.gentoo.org/wiki/Handbook:X86/Working/EnvVar

Variable Description 描述
PATH This variable contains a colon-separated list of directories in which the system looks for executable files. If a name is entered of an executable (such as ls, rc-update, or emerge) but this executable is not located in a listed directory, then the system will not execute it (unless the full path is entered as the command, such as /bin/ls). 此变量包含以冒号分隔的目录列表,系统在其中查找可执行文件。如果输入了可执行文件的名称(例如ls,rc-update或emerge),但此可执行文件不在列出的目录中,则系统不会执行它(除非输入完整路径作为命令,例如中的/ bin / LS)。
ROOTPATH This variable has the same function as PATH, but this one only lists the directories that should be checked when the root-user enters a command. 此变量与PATH具有相同的功能,但此变量仅列出root用户输入命令时应检查的目录。
LDPATH This variable contains a colon-separated list of directories in which the dynamical linker searches through to find a library. 此变量包含以冒号分隔的目录列表,动态链接器在其中搜索以查找库。
MANPATH This variable contains a colon-separated list of directories in which the man command searches for the man pages. 此变量包含以冒号分隔的目录列表,man命令在其中搜索手册页。
INFODIR This variable contains a colon-separated list of directories in which the info command searches for the info pages. 此变量包含以冒号分隔的目录列表,info命令在其中搜索信息页面。
PAGER This variable contains the path to the program used to list the contents of files through (such as less or more). 此变量包含用于列出文件内容的程序的路径(例如,更少或更多)。
EDITOR This variable contains the path to the program used to change the contents of files with (such as nano or vi). 此变量包含用于更改文件内容的程序的路径(例如nano或vi)。
KDEDIRS This variable contains a colon-separated list of directories which contain KDE-specific material. 此变量包含以冒号分隔的目录列表,其中包含特定于KDE的材料。
CONFIG_PROTECT This variable contains a space-delimited list of directories which should be protected by Portage during updates. 此变量包含以空格分隔的目录列表,在更新期间应由Portage保护。
CONFIG_PROTECT_MASK This variable contains a space-delimited list of directories which should not be protected by Portage during updates. 此变量包含以空格分隔的目录列表,在更新期间不应受Portage保护。


Below is an example definition of all these variables:
PATH="/bin:/usr/bin:/usr/local/bin:/opt/bin:/usr/games/bin"
ROOTPATH="/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin"
LDPATH="/lib:/usr/lib:/usr/local/lib:/usr/lib/gcc-lib/i686-pc-linux-gnu/3.2.3"
MANPATH="/usr/share/man:/usr/local/share/man"
INFODIR="/usr/share/info:/usr/local/share/info"
PAGER="/usr/bin/less"
EDITOR="/usr/bin/vim"
KDEDIRS="/usr"
CONFIG_PROTECT="/usr/X11R6/lib/X11/xkb /opt/tomcat/conf \
/usr/kde/3.1/share/config /usr/share/texmf/tex/generic/config/ \
/usr/share/texmf/tex/platex/config/ /usr/share/config"
CONFIG_PROTECT_MASK="/etc/gconf"