Path: utzoo!utgpu!news-server.csri.toronto.edu!bonnie.concordia.ca!thunder.mcrcim.mcgill.edu!snorkelwacker.mit.edu!bloom-beacon!eru!hagbard!sunic!mcsun!hp4nl!star.cs.vu.nl!maart From: maart@cs.vu.nl (Maarten Litmaath) Newsgroups: comp.unix.shell Subject: Re: sh loop variable and "double indirection" Message-ID: <8873@star.cs.vu.nl> Date: 29 Jan 91 15:43:10 GMT References: <1991Jan27.044258.18779@shibaya.lonestar.org> Sender: news@cs.vu.nl Reply-To: maart@cs.vu.nl (Maarten Litmaath) Organization: VU Dept. of Computer Science, Amsterdam, The Netherlands Lines: 48 In article , krs@uts.amdahl.com (Kris Stephens [Hail Eris!]) writes: )In article <1991Jan27.044258.18779@shibaya.lonestar.org> ) afc@shibaya.lonestar.org (Augustine Cano) writes: )>I am trying to specify (at run time) an upper limit for a loop in a shell )>script. In pseudo-code the ideal would be something like this: )> )>read i )>for 0 to i )>do )>... )>done ) )Let me give you the ksh version first, then the (slower) sh mods -- it's )slower because each iteration requires a fork/exec not required in ksh. Not necessarily. read i t0= rest='1 2 3 4 5 6 7 8 9' for h in '' $rest do for t in "$t0" $rest do for u in 0 $rest do case $h$t$u in 999) echo overflow >&2 exit 1 ;; $i) break 3 esac do_something done done t0=0 done This example works for 999 iterations. Enough? -- kinnersley@kuhub.cc.ukans.edu (Bill Kinnersley): "Do phonograph turntables turn the other way in Australia?" gjh@krebs.acc.Virginia.EDU (Galen J. Hekhuis): "How do you think satanic messages were discovered on records?"