基础知识 day-18 (复习,扩展: bashrc和bash_profile)

【.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用户家目录下执行
[hadoop@hclient2 ~]$ echo “invoke hclient2:~/.bashrc”>>.bashrc
[hadoop@hclient2 ~]$ 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

[hadoop@hclient2 ~]$
2、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 ~]$
3、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 文件中。因为不管是登陆还是不登陆,该文件总会被调用!

正则表达式特殊字符

\b 左边界 & 代表// 里的内容
. 任意一个字符

  • 表示 前面这个字符有0或者多个 (abc* ab也符合)
  • .* 表示所有
    ? 前面的字符有0个或者1个 (a1?== a or a1)
  • 前面的字符有1个或多个

扩展正则 grep -E 否则不能识别? +等特殊符号
sed -r
awk 什么不用加

或者 egrep ‘abc|123’ 1.txt
[ ] 表示方括号里面的1个字符 【a-zA-Z0-9】任意一个字符
[abc] 要么 a b c [a|@] 表示要么是a或| 或@ [^] 非
^ 表示开头 $表示结尾
{表示范围} a{1,5} 1至5个a b{3} 3个b了
()小括号里面的字符看成一个整体 (abc){2} 表示abcabc (abc)+ 1个或者多个abc
abc{2} 表示 abcc

awk -F ‘[#?]’ 分隔符可以是 # 或: 或 |

你可能感兴趣的:(基础知识 day-18 (复习,扩展: bashrc和bash_profile))