在Debian环境(以及大多数类Unix系统)中,环境变量的优先级通常遵循以下规则:
~/.bashrc
或 ~/.profile
:
~/.bashrc
会被加载;如果是登录shell,~/.profile
(或~/.bash_profile
)会被加载。/etc/profile
:
/etc/environment
:
/etc/profile.d/
目录下的脚本:
/etc/profile
加载。/etc/profile
中的同名变量。在shell中直接赋值:
export VARIABLE=value
命令设置的变量具有最高的优先级。~/.bash_aliases
或 ~/.bash_functions
:
~/.bashrc
或 ~/.profile
/etc/profile.d/
目录下的脚本/etc/profile
/etc/environment
/etc/sysctl.conf
等)zsh
和fish
。env
命令可以查看当前shell会话中的所有环境变量。通过理解这些优先级规则,你可以更有效地管理和调试Debian环境中的环境变量。