Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!watmath!clyde!burl!ulysses!allegra!bellcore!decvax!genrad!mit-eddie!godot!ima!johnl From: johnl@ima.UUCP Newsgroups: net.unix Subject: Re: why doesn't this shell program work Message-ID: <503@ima.UUCP> Date: Sun, 3-Mar-85 23:48:35 EST Article-I.D.: ima.503 Posted: Sun Mar 3 23:48:35 1985 Date-Received: Thu, 7-Mar-85 05:29:57 EST Lines: 27 Nf-ID: #R:drutx:-214700:ima:19700009:000:888 Nf-From: ima!johnl Mar 3 20:54:00 1985 Congratulations! You have tripped over one of the most peculiar parts of the Bourne shell. The problem is this: the shell only knows how to do I/O redirection for processes, not for builtin commands. This means that if you redirect I/O for a command, it gets forked into a subprocess silently and confusingly. For example: a=one for i in two three four do a=$i done > plugh echo $a The result is "one" because the for loop is done in a subprocess, and the modifications to variable a in the subprocess don't affect the top level shell. See Steve Bourne's book "The Unix System" for some extremely gross ways to work around this. (I suppose that since it's his shell, he gets to program it any way he wants, though.) Also, the System V shell is somewhat smarter about I/O redirection, so some things like "read foo