Re: bash increment in a given way

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]



On Sat, Dec 11, 2010 at 8:34 AM, S Mathias <smathias1972@xxxxxxxxx> 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.

-- 
  Les Mikesell
   lesmikesell@xxxxxxxxx
_______________________________________________
CentOS mailing list
CentOS@xxxxxxxxxx
http://lists.centos.org/mailman/listinfo/centos


[Index of Archives]     [CentOS]     [CentOS Announce]     [CentOS Development]     [CentOS ARM Devel]     [CentOS Docs]     [CentOS Virtualization]     [Carrier Grade Linux]     [Linux Media]     [Asterisk]     [DCCP]     [Netdev]     [Xorg]     [Linux USB]
  Powered by Linux