for loops

Kris Stephens [Hail Eris!] krs at uts.amdahl.com
Sat Apr 6 03:34:24 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

#### ksh fragment ####
while [ $FILES -ge 0 ]
do
	echo "$FILES"
	((FILES -= 1))	# or ((FILES = $FILES - 1))
done
#### ksh fragment ####

...Kris
-- 
Kristopher Stephens, | (408-746-6047) | krs at uts.amdahl.com | KC6DFS
Amdahl Corporation   |                |                    |
     [The opinions expressed above are mine, solely, and do not    ]
     [necessarily reflect the opinions or policies of Amdahl Corp. ]



More information about the Comp.unix.shell mailing list