Re: [SLUG] Counting up in a shell script
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
Re: [SLUG] Counting up in a shell script
On Sat, 2003-08-30 at 03:14, Ben de Luca wrote: just for interest is there a way? of doing this so its entirely in /bin/sh? there by making it portable Both solutions work in sh for me. oh and is this html mail? Well, if it is it renders as an extremely good counterfeit plain-text mail in evolution. James. On Friday, August 29, 2003, at 01:10 PM, 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 - Jeff -- linux.conf.au 2004: Adelaide, Australia http://lca2004.linux.org.au/ Laughter is a force for democracy. - John Cleese -- SLUG - Sydney Linux User's Group - http://slug.org.au/ More Info: http://lists.slug.org.au/listinfo/slug -- SLUG - Sydney Linux User's Group - http://slug.org.au/ More Info: http://lists.slug.org.au/listinfo/slug
Re: [SLUG] Counting up in a shell script
Ben de Luca wrote: just for interest is there a way? of doing this so its entirely in /bin/sh? there by making it portable They key to doing arithmetic in the shell is 'let', which operates on environment variables sans dollar sign: n=10 let i=1 while [ $i -lt $n ]; do echo $i let i=i+1 done -- _ Rick Welykochy || Praxis Services A low voter turnout is an indication of fewer people going to the polls. -- Dan Quayle -- SLUG - Sydney Linux User's Group - http://slug.org.au/ More Info: http://lists.slug.org.au/listinfo/slug
[SLUG] Counting up in a shell script
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 - Doug -- SLUG - Sydney Linux User's Group - http://slug.org.au/ More Info: http://lists.slug.org.au/listinfo/slug
Re: [SLUG] Counting up in a shell script
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 - Jeff -- linux.conf.au 2004: Adelaide, Australia http://lca2004.linux.org.au/ Laughter is a force for democracy. - John Cleese -- SLUG - Sydney Linux User's Group - http://slug.org.au/ More Info: http://lists.slug.org.au/listinfo/slug
Re: [SLUG] Counting up in a shell script
just for interest is there a way? of doing this so its entirely in /bin/sh? there by making it portable oh and is this html mail? On Friday, August 29, 2003, at 01:10 PM, 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 - Jeff -- linux.conf.au 2004: Adelaide, Australia http://lca2004.linux.org.au/ Laughter is a force for democracy. - John Cleese -- SLUG - Sydney Linux User's Group - http://slug.org.au/ More Info: http://lists.slug.org.au/listinfo/slug -- SLUG - Sydney Linux User's Group - http://slug.org.au/ More Info: http://lists.slug.org.au/listinfo/slug