Re: sh bug?

From: Dan Nelson <dnelson_at_allantgroup.com>
Date: Fri, 28 Jan 2005 11:14:29 -0600
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
Received on Fri Jan 28 2005 - 16:14:36 UTC

This archive was generated by hypermail 2.4.0 : Wed May 19 2021 - 11:38:27 UTC