tim@cithep.UucP (Tim Smith ) (03/31/85)
Ok, I see why
if true
x
y
z
fi
runs all but the last command in a subshell. I should have
realized that. But I have still not received an explanation
for the first problem I had. That concerned this construct:
number=one
while something
do
number=two
done < TheLarch
I wondered why the assignment in the loop was not done. Several people
correctly pointed out that the body of the loop is done in a subshell,
so the assignment does not show up outside the loop. Ok, fine. And now
the question.
Why is the body of the loop done in a subshell? Could it
not use dup() to save the current stdin, and put it back after
the loop? This is crtainly what I expected.
If you feel like answering this, and are one of the following people,
please post to the net to settle this once and for all:
Goug Gwyn, Guy Harris, Henry Spencer, Chris Torek, Norman Wilson
Otherwise, mail rather than post!
--
Duty Now for the Future
Tim Smith
ihnp4!{wlbr!callan,cithep}!timhenry@utzoo.UUCP (Henry Spencer) (04/03/85)
> number=one > while something > do > number=two > done < TheLarch > > Why is the body of the loop done in a subshell? Could it > not use dup() to save the current stdin, and put it back after > the loop? This is crtainly what I expected. The quick answer is, it should. If you interpose a shell function (only found in more recent Bourne shells) between the loop and the redirection, it does it right. When redirection of builtin commands was added to the shell -- post-V7 -- all the machinery that would be needed was added. It just hasn't been applied to this case yet. -- Henry Spencer @ U of Toronto Zoology {allegra,ihnp4,linus,decvax}!utzoo!henry