.profile 和 .bashrc 在我的 Mac 上不起作用

29 terminal bash .profile macos

这个问题我已经很久了。运行终端 .profile 后,.bashrc 文件不起作用(未执行)。你能指出我应该在哪里寻找问题的根源吗?

小智 40

.profile没有运行也有类似的问题。事实证明(如Apple StackExchange answer 中所述),如果您有.bash_profile.bash_login文件,那么您.profile将被 bash 忽略。

  • 这个答案对我有帮助。在我安装了 `rvm` 之后添加了 `.bash_login`。 (5认同)
  • 我的问题是我安装了 Python,它自动创建了一个 .bash_profile 文件,导致我的 .profile 无法运行。 (2认同)

小智 17

我想这个问答应该交给超级用户,但无论如何:

根据手册页的调用部分,

  • /etc/profile~/.profile为交互式登录外壳读取,以及
  • ~/.bashrc 为交互式非登录外壳读取。

如果您的其他 UNIX 机器~/.bashrc即使对于交互式登录 shell 也能自动读取,那是因为系统范围/etc/ profile内有一行读取~/.bashrc. OS X 的系统范围/etc/profile内没有。

因此,如果您~/.bashrc甚至想为交互式登录 shell 运行,则需要包含一行

. ~/.bashrc
Run Code Online (Sandbox Code Playgroud)

在您的~/.profile.