.bash_profile 与 .bashrc 的区别

【.bash_profile 与 .bashrc 的区别】
.bash_profile is executed for login shells, while .bashrc is executed for interactive non-login shells.
 
【login shell 与 non-login shell 的区别】
1、当你直接在机器login界面登陆、使用ssh登陆或者su切换用户登陆时,.bash_profile 会被调用来初始化shell环境
Note:.bash_profile文件默认调用.bashrc文件
.bash_profile中有如下内容
if [ -f ~/.bashrc ]; then
        . ~/.bashrc
fi 
2、当你不登陆系统而使用ssh直接在远端执行命令,.bashrc 会被调用
3、当你已经登陆系统后,每打开一个新的Terminal时,.bashrc 都会被再次调用。
 
准备工作
在hbasetest02机器的root用户下

[@rsync.slave02.hbasetest.hb.ted ~]# vim .bashrc
echo "hbase test02 ~/.bashrc"

[@rsync.slave02.hbasetest.hb.ted ~]# vim .bash_profile
echo "hbase test02 ~/.bash_profile"

 

Login Shell
1、窗口登陆

Last login: Wed Apr 22 09:28:43 2020 from 10.129.148.159
hbase test02 ~/.bashrc
hbase test02 ~/.bash_profile
[@rsync.slave02.hbasetest.hb.ted ~]#

 

2、SSH 登陆

 

[@rsync.slave01.hbasetest.hb.ted ~]# ssh rsync.slave02.hbasetest.hb.ted
root@rsync.slave02.hbasetest.hb.ted's password:
Last login: Wed Apr 22 10:12:44 2020 from 10.129.148.159
hbase test02 ~/.bashrc
hbase test02 ~/.bash_profile

 

3、su 登陆

[@rsync.slave02.hbasetest.hb.ted ~]$ su - root
Password:
Last login: Wed Apr 22 10:13:32 CST 2020 from 10.160.58.41 on pts/1
hbase test02 ~/.bashrc
hbase test02 ~/.bash_profile

 

Non-login Shell:
Note: ssh ...[user@] hostname [command]
If command is specified, it is executed on the remote host instead of a login shell.
 

[@rsync.slave01.hbasetest.hb.ted ~]# ssh rsync.slave02.hbasetest.hb.ted "hostname"
root@rsync.slave02.hbasetest.hb.ted's password:
hbase test02 ~/.bashrc
rsync.slave02.hbasetest.hb.ted

 

 

 

posted on 2020-04-22 10:17  gentleman_hai  阅读(263)  评论(0编辑  收藏  举报

导航