-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 According to Bruno Haible on 9/18/2006 9:20 AM: > Ralf Wildenhues wrote: >> Hmm, ok. But traditional shells execute this construct >> while read foo >> do >> $whatever >> done <$file >> >> in a subshell, too, for example Solaris 10 sh. > > Ouch. Looking at the variables, it indeed behaves like a subshell. > Looking at the process id, it does not...!
This is to be expected - POSIX states that $$ is special, and that in a subshell, it is not the pid of the current process, but the pid of the original process. http://www.opengroup.org/onlinepubs/009695399/utilities/xcu_chap02.html#tag_02_05_02 "In a subshell (see Shell Execution Environment ), '$' shall expand to the same value as that of the current shell." "A subshell environment shall be created as a duplicate of the shell environment, except that signal traps set by that shell environment shall be set to the default values. Changes made to the subshell environment shall not affect the shell environment. Command substitution, commands that are grouped with parentheses, and asynchronous lists shall be executed in a subshell environment. Additionally, each command of a multi-command pipeline is in a subshell environment; as an extension, however, any or all commands in a pipeline may be executed in the current environment. All other commands shall be executed in the current shell environment." While you can use $SHLVL to tell whether you are in a subshell, and then use a helper sub-process to report the ppid (and thus the subshell's pid), there is no portable way to tell the pid of a subshell from within the subshell. http://lists.gnu.org/archive/html/bug-bash/2006-09/msg00068.html - -- Life is short - so eat dessert first! Eric Blake [EMAIL PROTECTED] -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.2.1 (Cygwin) Comment: Public key at home.comcast.net/~ericblake/eblake.gpg Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iD8DBQFFD+fD84KuGfSFAYARAq3TAKDUd2GLiDNo1a4m0FRjo4Bv3pNeqgCeNunQ w4vwGrZ/zzxPaHD8BBLfP1E= =XQDL -----END PGP SIGNATURE-----