Ubuntu 环境变量加载
- /etc/environment
/etc/environment 不是 script 脚本,而是让PAM解析的简单文本, 故不能使用命令, 变量, 每行都是简单的 name=value, # 用来注释,最先加载
- /etc/profile
- /etc/bash.bashrc

-
~/.bashrc


- ~/.profile
- 额外创建 /etc/profile.d/init.sh
- 测试脚本
- 交互 登录 shell
1) 加载 /etc/profile , /etc/profile 加载了 /etc/bash.bashrc 和 /etc/profile.d/*.sh
2) 加载 ~/.profile, ~/.profile 加载了 ~/.bashrc
测试脚本执行结果:
变量 gash = /root/.profile
-
交互式 非登录 shell
/etc/bash.bashrc => ~/.bashrc 加载了两个 bashrc 交互式配置文件, gash = ~/.bashrc
- 登录 非交互 shell
1) /etc/profile, 但由于为 非交互, 故 /etc/bash.bashrc 没有被加载
2) ~/.profile, 但由于为 非交互, 故 ~/.bashrc 没有被加载
可以发现 加载 的文件与 登录 交互 shell 一样, 但不满足判定调节, 故两个 交互shell的配置文件 ( /etc/bash.bashrc, ~/.bashrc) 没有被加载 - 非登录 非交互
没有加载任何 环境配置文件

浙公网安备 33010602011771号