从 .bash_profile 加载 .profile 还是根本不使用 bash_profile?

Lol*_*olo 3 environment-variables

我在运行 Yosemite 的 MAC 上。

直到最近,我只有一个 .profile,其中我将目录添加到我的 PATH 中。

现在我有一个 .bash_profile,根据我的经验和后来在网上阅读的内容,它会导致打开终端窗口时忽略 .profile。

经过一些阅读后,我确实了解 .pofile 和 .bash_profile 有何不同。我确实知道 .bash_profile 仅在启动 shell 时被调用。

然而,我仍然不确定,对于基本用户来说,以下任一方面的缺点(如果有的话)是什么:

  • 从 .bash_profile 调用 .profile,
  • 或者直接忽略 .bash_profile 并直接从 .profile 文件中的 shell 设置我可能需要的所有环境变量。

例如,我在这里读到,由于 .bash_profile 存在时 .profile 被忽略,所以我可以添加

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

在我的 bash_profile 中调用 .profile。

或者,虽然我知道 .bash_profile 允许我设置 bash 之外不需要的变量,但我仍然可以在 .profile 中设置我需要的所有内容,并且看不到使用 .bash_profile 给我带来了什么。

Gil*_*il' 8

传统 sh 在启动时读取该文件~/.profile(当它是登录 shell时) 。

\n\n

Bash 向后兼容 sh 但提供附加功能,读取.bash_profile,如果不存在,则尝试.profile改为 \xc2\xb9。当您的登录 shell 是 bash 时,这允许您使用.profile普通的 sh 并.bash_profile利用 bash 的额外功能。

\n\n

.bashrc当交互调用时,Bash 还会读取另一个文件。这是放置提示、别名、完成设置等的地方。但是,它不会在交互式登录 shell 中读取该文件。因此,您.bash_profile应该.bashrc在 shell 交互运行 \xe2\x80\x94 时获取源代码,否则您必须维护单独的文件。

\n\n

几乎没有任何理由偏离以下内容.bash_profile

\n\n
. ~/.profile\ncase $- in *i*) . ~/.bashrc;; esac\n
Run Code Online (Sandbox Code Playgroud)\n\n

将登录时的内容(例如环境变量定义).profile和交互式 shell 的内容放入.bashrc.

\n\n

如果您只使用 bash 作为登录 shell,则可能没有.profile,并将登录时的内容直接放入 中.bash_profile,再加上交互时要加载的行.bashrc

\n\n

\xc2\xb9之前也尝试过,但这并不是很有用。.bash_login.profile

\n


归档时间:

查看次数:

7829 次

最近记录:

10 年,5 月 前