Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!pacific.mps.ohio-state.edu!linac!midway!clout!chinet!les From: les@chinet.chi.il.us (Leslie Mikesell) Newsgroups: comp.unix.shell Subject: Re: problems with 'while read' Message-ID: <1991May07.031652.1083@chinet.chi.il.us> Date: 7 May 91 03:16:52 GMT References: <3635@dagobert.informatik.uni-kiel.dbp.de> Organization: Chinet - Chicago Public Access UNIX Lines: 27 In article <3635@dagobert.informatik.uni-kiel.dbp.de> wib@informatik.uni-kiel.dbp.de (Willi Burmeister) writes: >while read num >do > echo "do something with <$num>" > last=$num >done < hugo > >echo "last num = <$last>" This creates a subshell to run the redirected loop. Thus, outside of the loop, variables are unaffected. If no other redirections are needed, just redirect the whole script. If they are, you may be able to use parens to force the subshell to contain the part that needs the affected variable: ( while read num do echo "do something with <$num>" last=$num done echo "last num = <$last>" ) < hugo Les Mikesell les@chinet.chi.il.us