It's ok, that i can use this, when i want an incrementing sequence, in a given way:
# {START..END..INCREMENT} $ for i in {0..10..2}; do echo "Welcome $i times"; done Welcome 0 times Welcome 2 times Welcome 4 times Welcome 6 times Welcome 8 times Welcome 10 times $
but what's the "magic" for this? :
$ MAGIC; do echo "Welcome $i times"; done Welcome 0 times Welcome 1 times Welcome 4 times Welcome 5 times Welcome 8 times Welcome 9 times $
thanks:\
On Sat, Dec 11, 2010 at 06:34:25AM -0800, S Mathias wrote:
# {START..END..INCREMENT} $ for i in {0..10..2}; do echo "Welcome $i times"; done
but what's the "magic" for this? :
$ MAGIC; do echo "Welcome $i times"; done Welcome 0 times Welcome 1 times Welcome 4 times Welcome 5 times Welcome 8 times Welcome 9 times
You might just have to hard-code the sequence:
for i in 0 1 4 5 8 9; do ....
On 12/11/2010 03:41 PM, Stephen Harris wrote:
On Sat, Dec 11, 2010 at 06:34:25AM -0800, S Mathias wrote: You might just have to hard-code the sequence:
for i in 0 1 4 5 8 9; do ....
You can use seq (see: man seq)
for i in `seq FIRST INCREMENT LAST` ; do echo $i done;
bingo. :)
Thanks!!! :)
--- On Sat, 12/11/10, Mihai T. Lazarescu mtlagm@gmail.com wrote:
From: Mihai T. Lazarescu mtlagm@gmail.com Subject: Re: [CentOS] bash increment in a given way To: centos@centos.org Date: Saturday, December 11, 2010, 4:05 PM
On 12/11/2010 03:41 PM, Stephen Harris wrote:
On Sat, Dec 11, 2010 at 06:34:25AM -0800, S Mathias wrote: You might just have to hard-code the sequence:
for i in 0 1 4 5 8 9; do ....
This outputs:
for i in $(seq 0 4 16); do seq $i 1 $i+1; done 0 1 4 5 8 9 12 13 16 17
Mihai _______________________________________________ CentOS mailing list CentOS@centos.org http://lists.centos.org/mailman/listinfo/centos
On Sat, Dec 11, 2010 at 8:34 AM, S Mathias smathias1972@yahoo.com wrote:
It's ok, that i can use this, when i want an incrementing sequence, in a given way:
# {START..END..INCREMENT} $ for i in {0..10..2}; do echo "Welcome $i times"; done Welcome 0 times Welcome 2 times Welcome 4 times Welcome 6 times Welcome 8 times Welcome 10 times $
The old-school bourne compatible way is:
START=0 END=10 i=$START while [ "$i" -le "$END" ] do echo "Welcome $i times" i=`expr $i + 1` done
But for a small number of iterations I'd just use for with a list.