Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Iterating through a range of ints in ksh?

Tags:

shell

ksh

How can I iterate through a simple range of ints using a for loop in ksh?

For example, my script currently does this...

for i in 1 2 3 4 5 6 7
do
   #stuff
done

...but I'd like to extend the range way above 7. Is there a better syntax?

like image 814
razlebe Avatar asked Oct 19 '09 20:10

razlebe


3 Answers

Curly brackets?

for i in {1..7}
do
   #stuff
done
like image 103
martin clayton Avatar answered Sep 30 '22 15:09

martin clayton


While loop?

while [[ $i -lt 1000 ]] ; do
    # stuff
   (( i += 1 ))
done
like image 15
Lance Rushing Avatar answered Oct 04 '22 15:10

Lance Rushing


on OpenBSD, use jot:

for i in `jot 10`; do echo $i ; done;
like image 11
Colin Avatar answered Sep 30 '22 15:09

Colin