.profile .bash_profile和.bashrc之间的function区别是什么?

.profile.bash_profile.bashrc文件之间的function差异是什么?

.bash_profile.bashrc是特定于bash ,而.profile在没有自己的特定于shell的configuration文件的情况下被许多shell读取。 ( .profile被原始的Bourne shell使用。). .bash_profile.profile通过loginshell和.bashrc读取; 子壳体只读.bashrc 。 (在作业控制和现代窗口系统之间, .bashrc本身没有太多用处,如果你使用screen或者tmux ,screen / windows通常运行子shell而不是loginshell。)

这背后的想法是,一次性设置是由.profile (或其特定于shell的版本)和per-shell的.bashrc 。 例如,您通常只想在每次会话中加载一次环境variables,而不是在任何时候在会话中启动子shell,而不是重新启动它们,而您总是希望别名(不像环境variables那样自动传播)。

其他值得注意的shellconfiguration文件:

/etc/bash_profile (fallback /etc/profile )是在用户的.profile之前读取的,用于系统范围的configuration,并且在子shell中同样是/etc/bashrc (没有这个)。 包括Ubuntu在内的许多系统也使用包含shell脚本的/etc/profile.d目录.source )-ed从/etc/profile ; 这里的片段是per-shell, *.sh适用于所有的Bourne / POSIX兼容的shell和其他扩展应用于特定的shell。

根据bash手册页,.bash_profile被执行用于loginshell,而.bashrc被执行用于交互式非loginshell。

那么,什么是login或非loginshell?

当您通过控制台login(键入用户名和密码)时,无论是坐在机器上,还是通过ssh:.bash_profile远程执行,以在初始命令提示符之前configuration您的shell。 但是,如果您已经login到您的机器并在Gnome或KDE内部打开一个新的terminal窗口(xterm),那么.bashrc会在窗口命令提示符之前执行。 当你通过在terminalinput/ bin / bash来启动一个新的bash实例的时候.bashrc也会运行。

terminal窗口准则的一个例外是Mac OS X的Terminal.app,它默认为每个新的terminal窗口运行loginshell,调用.bash_profile而不是.bashrc。 其他的graphics用户界面terminal仿真器可以做同样的事情,但大多数人往往不会。

更多在这里http://www.joshstaiger.org/archives/2005/07/bash_profile_vs.html

.profile文件

.profile是与Bash没有特别关系的东西,比如环境variablesPATH和朋友,应该随时可用。

例如, .profile也应在启动graphics桌面会话时加载。


的.bashrc

.bashrc用于configuration交互式Bash用法,如Bash aliases ,设置您最喜欢的editor ,设置Bash prompt等。


.bash_profile中

.bash_profile用于确保.profile.bashrc都被加载到login shells

例如, .bash_profile可能是简单的

  . ~/.profile . ~/.bashrc 

如果您将忽略.bash_profile ,则只会加载.profile