( cmd ) 真的是在 sub shell 中运行的?

( cmd ) 真的是在 sub shell 中运行的?

复制内容到剪贴板
代码:
-(dearvoid@LinuxEden:tty3)-(~/tmp)-
[14009 0] ; echo $$
14009
-(dearvoid@LinuxEden:tty3)-(~/tmp)-
[14009 0] ; pid() { echo $$; }
-(dearvoid@LinuxEden:tty3)-(~/tmp)-
[14009 0] ; type pid
pid is a function
pid ()
{
    echo $$
}
-(dearvoid@LinuxEden:tty3)-(~/tmp)-
[14009 0] ; pid
14009
-(dearvoid@LinuxEden:tty3)-(~/tmp)-
[14009 0] ; export -f pid
-(dearvoid@LinuxEden:tty3)-(~/tmp)-
[14009 0] ; ( pid )
14009
-(dearvoid@LinuxEden:tty3)-(~/tmp)-
[14009 0] ; bash -c 'echo $PPID; echo $$; pid'
14009
14043
14043
-(dearvoid@LinuxEden:tty3)-(~/tmp)-
[14009 0] ; o
      
再给个例子:
复制内容到剪贴板
代码:
[dearvoid@LinuxEden:tty3 ~/tmp] ; echo $$
14070
[dearvoid@LinuxEden:tty3 ~/tmp] ; cat foo.sh
#!/bin/bash

echo " PID=$$"
echo "PPID=$PPID"
[dearvoid@LinuxEden:tty3 ~/tmp] ; ./foo.sh
PID=14278
PPID=14070
[dearvoid@LinuxEden:tty3 ~/tmp] ; ( ./foo.sh )
PID=14279
PPID=14070
[dearvoid@LinuxEden:tty3 ~/tmp] ; o