.bashrc 和 /etc/bash.bashrc 有什么区别?

Ili*_*ons 16 bash bashrc

.bashrc 和 /etc/bashrc

/etc/bash.bashrc和 和有~/.bashrc什么区别?

Joh*_*024 27

当 bash 在类似 Debian/Ubuntu 的系统上初始化非登录交互式 bash shell 时,shell 首先/etc/bash.bashrc读取~/.bashrc.

,之所以/etc/bash.bashrc没有出现正常的bash文档(如在这里点击这里)是,它是一个由Debian添加和被Ubuntu采用了功能。正如 Debian 解释的那样(readme.debian):

  1. 什么是/etc/bash.bashrc?它似乎没有记录。

Debian 版本的 bash 使用一个特殊选项 ( -DSYS_BASHRC) 进行编译,该选项使 bash/etc/bash.bashrc~/.bashrc 交互非登录 shell之前被读取。因此,在Debian系统, /etc/bash.bashrc~/.bashrc/etc/profile~/.bash_profile

因此,/etc/bash.bashrc在 Debian 和 Ubuntu 手册页中有记录,但在其他不支持此功能的发行版的手册页中没有记录。

更新:更多发行版

/etc/bash.bashrc 已经在 Debian 圈子之外被采用,因为评论表明它在 Arch Linux、MSYS2 和 Git Bash 等发行版中的使用。

  • 值得注意的是,使用正在蔓延。基于 MSYS2 的 Git bash 也有这个约定。它似乎被用来建立系统级适配/配置/标准。 (2认同)
  • [Archlinux 还在 `~/.bashrc` 之前获取 `/etc/bash.bashrc`](https://wiki.archlinux.org/index.php/Bash#Inspiration)。 (2认同)

Ili*_*ons 5

系统范围初始化文件/etc/bash.bashrc\n和标准个人初始化文件~/.bashrc\n(如果 shell 是 interactiv\xd0\xb5)。

\n