for loops
Steve Spicer
spicer at tci.UUCP
Fri Apr 5 08:07:04 AEST 1991
In article <2816 at maestro.htsa.aha.nl> miquels at maestro.htsa.aha.nl (Miquel van Smoorenburg) writes:
>In article <3693 at ux.acs.umn.edu> edh at 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 at 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
More information about the Comp.unix.shell
mailing list