.bash_profile、.bash_login、.bashrc和.profile做的都是差不多的事情:设置和定义函数、变量等。

主要区别在于,.bashrc是在打开非登录但交互的窗口时调用的,而.bash_profile和其他则是在登录 shell 时调用的。很多人都会让他们的.bash_profile或类似文件调用.bashrc。

Section 40.1: .profile 与 .bash_profile (和 .bash_login)

大多数 shell 启动时都会读取 .profile,包括 bash。然而,.bash_profile 用于 bash 的特定配置。如果是一般的初始化代码,可以放在 .profile中。如果是针对 bash 的,则使用 .bash_profile。

.profile实际上不是专门为 bash 设计的,而是 .bash_profile。(如果找不到.bash_profile,Bash 会使用.profile。

如果找不到 .bash_profile,.bash_login就是 .bash_profile 的后备。一般来说,最好使用 .bash_profile 或 .profile。