Ubuntu 环境变量加载

 

 

  1. /etc/environment

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

     

     

  2. /etc/profile

     

     

  3. /etc/bash.bashrc

     

     

     

     

  4.  

     ~/.bashrc

     

     

     

     

     

     

  5.  ~/.profile

     

     

  6. 额外创建 /etc/profile.d/init.sh

     

     

  7. 测试脚本

     

      

  8.  交互 登录 shell

     

     
    1) 加载 /etc/profile , /etc/profile 加载了 /etc/bash.bashrc 和 /etc/profile.d/*.sh
    2) 加载 ~/.profile, ~/.profile 加载了 ~/.bashrc

    测试脚本执行结果:

     

      变量 gash = /root/.profile

  9. 交互式 非登录 shell

     

     

    /etc/bash.bashrc => ~/.bashrc  加载了两个 bashrc 交互式配置文件, gash = ~/.bashrc

     

  10. 登录 非交互 shell

     

     

    1) /etc/profile, 但由于为 非交互, 故 /etc/bash.bashrc 没有被加载
    2) ~/.profile, 但由于为 非交互, 故 ~/.bashrc 没有被加载

    可以发现 加载 的文件与 登录 交互 shell 一样, 但不满足判定调节, 故两个 交互shell的配置文件 ( /etc/bash.bashrc, ~/.bashrc) 没有被加载

  11. 非登录 非交互

     

     
    没有加载任何 环境配置文件

posted @ 2021-07-16 15:37  ascertain  阅读(157)  评论(0编辑  收藏  举报