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 @   ascertain  阅读(170)  评论(0编辑  收藏  举报
编辑推荐:
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
阅读排行:
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 单元测试从入门到精通
· 上周热点回顾(3.3-3.9)
· winform 绘制太阳,地球,月球 运作规律
历史上的今天:
2020-07-16 if else实现排序
点击右上角即可分享
微信分享提示