sh bug?

Dan Nelson dnelson at allantgroup.com
Fri Jan 28 09:14:36 PST 2005


In the last episode (Jan 28), Julian Elischer said:
> Harti Brandt wrote:
> >On Fri, 28 Jan 2005, Julian Elischer wrote:
> >
> >JE>however  echo $$
> >JE>and
> >JE>  ( echo $$ )
> >JE>
> >JE>produce the same result.
> >
> >I think that the $$ is expanded in the old shell in any case.
> 
> hence my test of
> ps -l vs (ps -l)
> 
> unfortunatly the shell short circuits that too if it's too simple.

I think POSIX is careful to define a "subshell" as "a duplicate of the
shell environment [... where] changes made are not visible to the
parent shell environment".  They don't mention forking processes, which
allows shell authors to skip forking a separate shell process if they
can determine that there's no need for one.  I don't think there's any
way for a subshell to determine its own pid if you know it's running in
another process, even if it's an asynchronous one.  At least the parent
knows that pid, though, via $!.

-- 
	Dan Nelson
	dnelson at allantgroup.com


More information about the freebsd-current mailing list