Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!csd4.milw.wisc.edu!bionet!apple!vsi1!wyse!bob From: bob@wyse.wyse.com (Bob McGowen Wyse Technology Training) Newsgroups: comp.unix.questions Subject: Re: Bourne Shell FOR loop confusion Keywords: why does it do this Message-ID: <2346@wyse.wyse.com> Date: 3 Aug 89 18:38:20 GMT References: <689@msa3b.UUCP> Sender: news@wyse.wyse.com Reply-To: bob@wyse.UUCP (Bob McGowen Wyse Technology Training) Organization: Wyse Technology Lines: 39 In article <689@msa3b.UUCP> kevin@msa3b.UUCP (Kevin P. Kleinfelter) writes: >Would anyone who knows, please explain the following behavior? >(Post or e-mail, as you deem appropriate.) ---example code deleted--- > >***************************************** >What I really want to do is to redirect input to "read", but read is >non-redirectable (according to my doc, and experience on my system). ---deleted--- A little know fact about re-directing input to/from an sh loop is that the shell automatically forks another sh to run the loop. Thus, variables changed in the loop do NOT affect variables of the same name in the parent shell. May I suggest the following code to perform your desired redirction to the read command (btw, some newer versions of sh appear to support redirection to the read built-in --- several XENIX scripts I have looked at use this feature): while read line do ... done < file read returns failure on EOF and the loop then exits. Just remember that what you do in the loop may not be available to your script outside of the loop. One way around this would be to save items in a tmp file and either read the tmp file as needed or perhaps use the dot command on it: . tmp Hope this is helpful. Bob McGowan (standard disclaimer, these are my own ...) Customer Education, Wyse Technology, San Jose, CA ..!uunet!wyse!bob bob@wyse.com