交互式模式就是shell等待你的输入,而且执行你提交的命令。非交互式模式,在这种模式下,shell不与你进行交互,而是读取存放在文件中的命令,而且执行它们。shell
当第一个用户登陆时(login交互式shell),执行/etc/profile和~/.bash_profile;当运行bash shell时(nologin交互式shell),执行~/.bashrc。/etc/profile调用/etc/profile.d目录下的配置文件;~/.bash_profile会调用~/.bashrc;~/.bashrc会调用/etc/bashrc。bash
~/.bash_logout登出时执行一些清理任务ssh
在当前shell定义的alias只在当前shell生效ide
因此若是要全局声明别名或者变量的话:变量写在/etc/profile.d/目录下,别名写在/etc/bashrc下oop
【.bash_profile 与 .bashrc 的区别】
.bash_profile is executed for login shells, while .bashrc is executed for interactive non-login shells.
【login shell 与 non-login shell 的区别】
一、当你直接在机器login界面登录、使用ssh登录或者su切换用户登录时,.bash_profile 会被调用来初始化shell环境
Note:.bash_profile文件默认调用.bashrc文件
.bash_profile中有以下内容
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
二、当你不登录系统而使用ssh直接在远端执行命令,.bashrc 会被调用
三、当你已经登录系统后,每打开一个新的Terminal时,.bashrc 都会被再次调用。
测试准备工做
hclient2主机hadoop用户家目录下执行
[hadoop@hclient2 ~]$ echo "invoke hclient2:~/.bashrc">>.bashrc
[hadoop@hclient2 ~]$ echo "invoke hclient2:~/.bash_profile">>.bash_profile
Login Shell
一、窗口登录
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
[hadoop@hclient2 ~]$
二、SSH 登录
[hadoop@hserver ~]$ ssh hclient2
Last login: Mon Feb 25 22:42:19 2013 from hserver
invoke hclient2:~/.bashrc
invoke hclient2:~/.bash_profile
[hadoop@hclient2 ~]$
三、su 登录
[root@hclient2 ~]# 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.
[hadoop@hserver ~]$ ssh hclient2 hostname
invoke hclient2:~/.bashrc
hclient2
【故】若要配置环境变量之类,最保险是写在 .bashrc 文件中。由于无论是登录仍是不登录,该文件总会被调用!
测试