//使用括号在subshell执行命令
[root@localhost opt]# cat test4.sh
#!/bin/bash
echo $$
cd /test || (cd /boot;echo `pwd`;echo $$)
echo `pwd`
(
echo 1
echo $$
echo 1
sleep 60
)
echo $$
[root@localhost opt]#
[root@localhost opt]# ./test4.sh
9340
./test4.sh: 第 3 行:cd: /test: 没有那个文件或目录
/boot
9340
/opt
1
9340
1
//使用pstree查看,命令在新的进程执行
[root@localhost ~]# pstree -pa 9340
test4.sh,9340 ./test4.sh
└─test4.sh,9344 ./test4.sh
└─sleep,9345 60