Linux上环境变量问题

/ Linux_manage / 没有评论 / 1461浏览

废话少说,先上图

解读

  1. 首先读入的是全局环境变量设定目录/etc/profile,然后根据其内容读取额外的设定的文档,如 /etc/profile.d和/etc/inputrc
  2. 然后去用户家目录下,读取~/.bash_profile,否则读取~/.bash_login,再否则~/.profile,这三个文档设定基本上是一样的,存在读取优先关系
  3. 然后再去用户家目录下,读取~/.bashrc(一般情况下我们只能读取到该用户家目录下的.bashrc)

顺序应该为

  1. /etc/profile

  2. ~/.bash_profile

  3. ~/.bash_login

  4. ~/.profile

    /etc/profile 是必须要执行的,然后后面3个,按照顺序谁存在就执行谁,然后后面的就不会再执行

敲黑板

/etc/profile,/etc/bashrc 是系统全局环境变量设定

~/.profile,~/.bashrc是用户家目录下的私有环境变量设定

~/.profile与~/.bashrc的区别:

参考

https://blog.csdn.net/qq_40628847/article/details/80209494