tim@callan.UUCP (Tim Smith) (03/09/85)
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