您的位置:首页 > 运维架构 > Shell

.bash_profile vs .bashrc && /etc/profile vs /etc/bashrc

2011-08-08 18:49 381 查看


.bash_profile and .bashrc

According to the bash man page, .bash_profile is executed for login shells, while .bashrc is executed for interactive non-login shells.

Say, you’d like to print some lengthy diagnostic information about your machine each time you login (load average, memory usage, current users, etc). You only want to see it on login, so you only want to place this in your .bash_profile. If you put it in your
.bashrc, you’d see it every time you open a new terminal window.

Most of the time you don’t want to maintain two separate config files for login and non-login shells — when you set a PATH, you want it to apply to both. You can fix this by sourcing .bashrc from your .bash_profile file, then putting PATH and common settings
in .bashrc.

To do this, add the following lines to .bash_profile:

隐藏行号 复制代码 ?
Add the following line

if [ -f ~/.bashrc ]; then

source ~/.bashrc

fi

function CopyCode(key){var codeElement=null;var trElements=document.all.tags("ol");var i;for(i=0;i


Now when you login to your machine from a console .bashrc will be called.


/etc/profile and /etc/bashrc

/etc/profile is read in automatically only if the shell is a login shell.

/etc/profile contains system/global environment variables and startup programs. Since environment variables are persistent (each process started by a shell inherits them) it’s only needed to read them once. Similarly, once a startup program is launched, there
is no need to start it again.

Since /etc/bashrc is included by ~/.bashrc, and read every
time a shell starts up, people use it to include shell aliases and functions.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
相关文章推荐