How can I get the pid of a subshell?
For example:
$ echo $$
16808
This doesn't work, because the original shell expands $$
:
$ ( echo $$ )
16808
Why does single quoting not work? After the original shell removes the single quote, does the subshell not expand $$
in itself?
$ ( echo '$$' )
$$
Why does eval
not work either? Is eval
run by the subshell? Why does it give me the original shell's PID?
$ ( eval echo '$$' )
16808
Thanks.
$$
expansion" vs. "different pid in subshell").