在子进程里执行shell命令
shell 可以通过添加一个小括号的方式,让命令在子shell进程执行,和bash xxx.sh
执行效果一样,运行过程中设置的环境变量,cd,exit都不影响当前shell,如:
func1() {
(
cd /tmp
touch testfile
exit 0
)
}
shell 可以通过添加一个小括号的方式,让命令在子shell进程执行,和bash xxx.sh
执行效果一样,运行过程中设置的环境变量,cd,exit都不影响当前shell,如:
func1() {
(
cd /tmp
touch testfile
exit 0
)
}
原文地址:awk与cut在以空格为分割域时的区别
awk默认以空格为分割域,比如我想获得某进程pid:
[root@SHCTC-GAME12-44 ~]# ps -ef|grep "sshd -f"|grep -v grep
root 5088 1 0 14:28 ? 00:00:00 /usr/sbin/sshd -f /app/oslinkd/oslinkd_config
用awk如下写:
ps -ef|grep "sshd -f"|grep -v grep|awk '{print $2}'
这样即可获得pid : 5088
但是用cut,若以空格为分隔域,则并不是第二个域,而是第七个域,因为root与5088之间有6个空格:
ps -ef|grep "sshd -f"|grep -v grep|cut -d' ' -f7
结论:
awk 以空格为分割域时,是以单个或多个连续的空格为分隔符的;
cut则是以单个空格作为分隔符。