linux - 环境变量配置

  Linux 的环境变量可在多个文件中配置,如/etc/profile,/etc/profile.d/*.sh,~/.bashrc 等,下面说明上述几个文件之间的关系和区别。

  bash 的运行模式可分为 login shell 和 non-login shell。

  例如,我们通过终端,输入用户名、密码,登录系统之后,得到就是一个 login shell,而当我们执行以下命令 ssh hadoop103 command,在 hadoop103 执行 command 的就是一个non-login shell。

  这两种 shell 的主要区别在于,它们启动时会加载不同的配置文件,login shell 启动时会加载/etc/profile,non-login shell 启动时会加载~/.bashrc。

  而在加载~/.bashrc(实际是~/.bashrc 中加载的/etc/bashrc)或/etc/profile 时,都会执行如下代码片段,

  因此不管是 login shell 还是 non-login shell,启动时都会加载/etc/profile.d/*.sh 中的环境变量。

posted @ 2021-06-09 11:59  快乐的张小凡  阅读(40)  评论(0编辑  收藏  举报