幸福飞过海 - bash https://fengqi.me/tag/bash/ 在子进程里执行shell命令 https://fengqi.me/unix/728.html 2025-05-29T05:28:00+00:00 shell 可以通过添加一个小括号的方式,让命令在子进程执行,和bash xxx.sh执行效果一样,运行过程中设置的环境变量、cd、执行exit等都不影响当前shell,如:func1() { ( cd /tmp touch testfile exit 0 ) } 这里末尾执行exit并不会导致当前的shell退出,这对于行数很多需要提前退出的情况非常有用的。 [转载] awk与cut在以空格为分割域时的区别 https://fengqi.me/unix/266.html 2014-12-21T18:03:00+00:00 原文地址: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则是以单个空格作为分隔符。