At Fri, 29 Aug 2003 13:10:08 +1000, Jeff Waugh wrote: > <quote who="Douglas Stalker"> > > > In a shell script, is the a better (i.e.: more elegant) way to get a > > variable to cycle from 1 to another value (such as 100) > > > > Currently I am using: > > > > $ I=1 ; while [ "$I" -le "10" ]; do echo $I ; I=`expr $I + 1`; done > > for i in $(seq 1 10); do > echo $i > done
seq is good for short lists (such as 1 to 10), but no good for counting up to several thousand. Simple maths can be performed in the shell by using $(( ... )), ie: i=1 while [ $i -le 1000 ]; do echo $i i=$(( $i + 1 )) done -- - Gus -- SLUG - Sydney Linux User's Group - http://slug.org.au/ More Info: http://lists.slug.org.au/listinfo/slug
