Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sun-barr!newstop!exodus!ichthous.Eng.Sun.COM!mcgrew From: mcgrew@ichthous.Eng.Sun.COM (Darin McGrew) Newsgroups: comp.unix.shell Subject: Re: /bin/sh: How to retain variables set in a while loop? Keywords: sh, while loop, variables Message-ID: <9260@exodus.Eng.Sun.COM> Date: 6 Mar 91 23:34:53 GMT References: <1991Mar5.025314.2317@lingua.cltr.uq.OZ.AU> <9209@exodus.Eng.Sun.COM> Sender: news@exodus.Eng.Sun.COM Distribution: comp Organization: Sun Microsystems, Mt. View, Ca. Lines: 35 In article <9209@exodus.Eng.Sun.COM> I write: >I'd try avoiding putting the while loop into a subshell by doing >the io redirection in the parent shell. Your example becomes-- > > exec < $UIDRANGES > num=0 > while [ $num -le $choice ] > do > read minuid maxuid title > echo "DEBUG: $num $title $minuid $maxuid" > num=`expr $num + 1` > done < $UIDRANGES > > echo "After while: num=$num title=$title minuid=$minuid maxuid=$maxuid" This should really be-- exec < $UIDRANGES num=0 while [ $num -le $choice ] do read minuid maxuid title echo "DEBUG: $num $title $minuid $maxuid" num=`expr $num + 1` done echo "After while: num=$num title=$title minuid=$minuid maxuid=$maxuid" since the point was to eliminate the io redirection of the while loop. Darin McGrew mcgrew@Eng.Sun.COM "Christianity isn't a crutch; it's a stretcher. Affiliation stated for You can't even hobble into heaven." identification purposes only.