Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!pacific.mps.ohio-state.edu!linac!midway!ux1.cso.uiuc.edu!maverick.ksu.ksu.edu!iowasp.physics.uiowa.edu!ceres.physics.uiowa.edu!news.iastate.edu!sharkey!caen!sdd.hp.com!think.com!paperboy!hsdndev!rutgers!bagate!tci!spicer From: spicer@tci.UUCP (Steve Spicer) Newsgroups: comp.unix.shell Subject: Re: for loops Keywords: sh: for i to $FILES Message-ID: <523@tci.UUCP> Date: 4 Apr 91 22:07:04 GMT References: <3693@ux.acs.umn.edu> <2816@maestro.htsa.aha.nl> Reply-To: spicer@tci.bell-atl.com (Steven Spicer) Followup-To: comp.unix.shell Organization: Technology Concepts Inc. Sudbury MA Lines: 37 In article <2816@maestro.htsa.aha.nl> miquels@maestro.htsa.aha.nl (Miquel van Smoorenburg) writes: >In article <3693@ux.acs.umn.edu> edh@ux.acs.umn.edu (Merlinus Ambrosius) writes: >>In sh, I'd like to do something like a BASIC for loop. Say I have $FILES >>set to some number, and I'd like to go through a loop $FILES times. Can >>this be done in sh? > >POSIX states that sh(1) should be able to evaluate expressions, >so you can do something like >while [ $FILES != 0 ] >do > echo -n '* ' > FILES=$[$FILES - 1] >done > >But I haven't seen a sh anywhere that is already capable of doing this >(not even the one I am writing myself for Minix... yet.). >Maybe somebody knows if a new ksh can do this? ksh allows this (which I tested before posting) $ integer i=5 $ while (( i > 0 )) ; do > print $i > (( i = i - 1 )) >done 5 4 3 2 1 $ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Steven Spicer/spicer@tci.bell-atl.com Is your design so simple that there are obviously no deficiencies, or so complicated that there are no obvious deficiencies? -- suggested by a quote from C.A.R. Hoare