Re(2): shell bug I reported here a f
johnl at ima.UUCP
johnl at ima.UUCP
Tue Mar 12 14:44:32 AEST 1985
> if true
> then
> parent
> parent
> parent
> fi < /dev/null
>
> shows the first two 'parent' commands are run from a subshell, while the
> third is run from the main shell! What IS going on?
Glad you asked. In fact, all three of the "parent" programs are run from
a subshell. There is, however, a longstanding hack in the shell such that
the lexically last command in a subshell is exec'ed directly without an extra
fork, which saves a little time. This is what you're seeing.
All this goes to show that although the shell is a thing of wonder, its
semantics are not well specified. (The C Shell is even worse, lest people
think I'm biased.) The semantics I'd like to see would promise that all
variable setting be (effectively) in the top shell unless explicitly put in
a subshell by enclosing a sequence in parens. I realize this would be
tricky to implement, but it sure would make shell programming easier.
John Levine, ima!johnl
More information about the Comp.unix.wizards
mailing list