[arwild1@hplcsl027 ~]$ echo $$; ( set -x; eval echo \$$ )
7856
+ eval echo '$$'
++ echo 7856
7856
Needless to say I was surprised by the result. I had assumed that:
( echo $$; )
wouldn't work because the parent process (in this case, my interactive
shell) would do the variable substituation before running the
command... which is what led me to using eval and quoting... and based
on the set -x output... the eval does appear to be happening in the
subshell... but the lookup is returning an arguably incorrect value
(one which, in the case, would actually be the PPID).
Based on my reading of the bash man page... each subshell should have
its own command execution environment (it certainly has its own
process and pid )... and as such I would think my trick should work...
but it would appear that bash may taking some shortcuts here.
Could this be seen as a bug or is there something I'm overlooking? Is
there any other way to achieve what I want to do on bash 3.x ?
Thanks,
-Alan