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

.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

  1. 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.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值