Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!wuarchive!zaphod.mps.ohio-state.edu!usc!snorkelwacker.mit.edu!bloom-picayune.mit.edu!athena.mit.edu!jik From: jik@athena.mit.edu (Jonathan I. Kamens) Newsgroups: comp.unix.shell Subject: Re: /bin/sh: How to retain variables set in a while loop? Keywords: sh, while loop, variables Message-ID: <1991Mar7.022149.29423@athena.mit.edu> Date: 7 Mar 91 02:21:49 GMT References: <1991Mar5.025314.2317@lingua.cltr.uq.OZ.AU> <9209@exodus.Eng.Sun.COM> Sender: news@athena.mit.edu (News system) Distribution: comp Organization: Massachusetts Institute of Technology Lines: 18 In article <9209@exodus.Eng.Sun.COM>, mcgrew@ichthous.Eng.Sun.COM (Darin McGrew) writes: |> If the while loop has its stdio redirected in any way, it is put |> in a subshell. (Likewise with for loops, case statements, etc.) |> The subshell has no way to pass variables back to its parent |> shell. I just want to point out that this problem is eliminated in some newer versions of the bourne shell, and also in some other shells (including, I believe, bash and ksh) that use the bourne shell's language. Of course, the C shell gets around the problem by not allowing redirection into loops at all :-). -- Jonathan Kamens USnail: MIT Project Athena 11 Ashford Terrace jik@Athena.MIT.EDU Allston, MA 02134 Office: 617-253-8085 Home: 617-782-0710