[CentOS] bash increment in a given way

Les Mikesell lesmikesell at gmail.com
Sat Dec 11 16:52:53 UTC 2010


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

-- 
  Les Mikesell
   lesmikesell at gmail.com



More information about the CentOS mailing list