.profile 在我启动 bash 终端时没有运行

Dav*_*ria 19 bash .profile

当我启动 bash 终端时,我的 .profile 没有被执行。我没有 ~/.bash_profile 或 ~/.bash_login,所以 .profile 应该运行,对吗?还有什么问题?

Ric*_*lka 26

它不是登录外壳。

如果 shell 是登录 shell,它将查找 .bash_profile(如果存在),然后查找 .profile。其他 shell 查找 .bashrc

所以,你可以把你想要的东西放在 .bashrc 中的每个 shell 实例中,并且可能在 .profile 中有一个引用 .bashrc。

所以:.bashrc:

stuff you want
Run Code Online (Sandbox Code Playgroud)

.profile 结尾:

[ -n "$BASH" ] && [ -f ~/.bashrc ] && . ~/.bashrc
Run Code Online (Sandbox Code Playgroud)

  • 如果您使用的是 Gnome 终端,您可以执行 Edit->Profile Preferences,转到 Title and Command 选项卡,然后选中“Run command as a login shell”。然后它会在你打开终端时获取你的 .bash_profile 或 .profile ,正如预期的那样。 (2认同)

gow*_*eon 5

尝试使用~/.bashrc