linux下 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 都會被再次調用。
測試準備工作
hclient2主機hadoop用戶家目錄下執行
[[email protected] ~]$ echo "invoke hclient2:~/.bashrc">>.bashrc
[[email protected] ~]$ echo "invoke hclient2:~/.bash_profile">>.bash_profile
Login Shell
1、窗口登陸
Red Hat Enterprise Linux Server release 6.3 (Santiago)
Kernel 2.6.32-279.el6.x86_64 on an x86_64
hclient2 login: hadoop
Password:
Last login: Mon Feb 25 23:03:45 on tty1
invoke hclient2:~/.bashrc
invoke hclient2:~/.bash_profile
[[email protected] ~]$
2、SSH 登陸
[[email protected] ~]$ ssh hclient2
Last login: Mon Feb 25 22:42:19 2013 from hserver
invoke hclient2:~/.bashrc
invoke hclient2:~/.bash_profile
[[email protected] ~]$
3、su 登陸
[[email protected] ~]# su - hadoop
invoke hclient2:~/.bashrc
invoke hclient2:~/.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.
[[email protected] ~]$ ssh hclient2 hostname
invoke hclient2:~/.bashrc
hclient2
【故】若要配置環境變量之類,最保險是寫在 .bashrc 文件中。因為不管是登陸還是不登陸,該文件總會被調用!
本文出自 “12601871” 博客,請務必保留此出處http://12611871.blog.51cto.com/12601871/1943306
linux下 bash_profile和bashrc區別