shell脚本执行的区别
1 #!/bin/bash
2
3 . subshell-test.sh
4
5 echo "test.sh"
6 echo
7 echo
8 echo $$
9 echo "\$! = $!"
test.sh
1 #!/bin/bash
2
3 (echo "Subshell running...";echo " jeffrey is comming...";echo $$)
4
5 echo $!
6 echo "main..."
7 echo $$
subshell-test.sh
. subshell-test.sh: (注意点号后面有个空格)表示读取后面这个shell脚本中的内容在当前脚本中执行. 他不会另起子shell.
我的理解就是把subshell-test.sh中的内容copy到test.sh中执行。
因为二者PID是相同的:
jeffrey@jeffrey-Aspire-4743:~$ ./test.sh
Subshell running...
jeffrey is comming...
<strong>5196</strong>
main...
<strong>5196</strong>
test.sh
<strong>5196</strong>
$! =
./subshell-test.sh:是重新开启新的子shell
jeffrey@jeffrey-Aspire-4743:~$ ./test.sh
Subshell running...
jeffrey is comming...
<strong>5214</strong>
main...
<strong>5214</strong>
test.sh
<strong>5213</strong>
$! =