shell bug I reported here a few days ago

Tim Smith tim at callan.UUCP
Sat Mar 9 10:40:18 AEST 1985


A few days ago, I mentioned here that the sh command

	for i in x
	do
		foo=bar
	done < /dev/null

failed to work.  The assignment was not done.  When IO was not redirected,
it worked.  It has since been pointed out to me that the for loop is run in
a subshell when IO is redirected, so of course, the assignment does not
have any effect outside the loop.  This does seem to be the case.  So
why is it done like this?  Why must the for loop be a subshell?

After finding out the above, I tried the following:

	parent		# parent prints the pid of its parent
	foo=bar
	if true
	then
		parent
		foo=spam
	fi < /dev/null
	echo $foo

This one is NOT running in a subshell, but the assignment STILL fails.  When
IO is not redirected, the assignment works.  What is going on in this case?

Note: the first example was tried on both a UniSoft port of Sys V and on the
system III sh.  I have only tried the second on the Sys V sh.
-- 
Duty Now for the Future
					Tim Smith
			ihnp4!wlbr!callan!tim or ihnp4!cithep!tim



More information about the Comp.unix.wizards mailing list