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

Re: bash increment in a given way



Let me understand: you want to accomplish that with a single loop,
right? I think so, because the following two nested loops do what you
want very easily:

for((i=0;i<=30;i+=4)); do 
  for((j=0; j<2;j++)); do 
    echo "Welcome $((i+j)) times"; 
  done;
done

Welcome 0 times
Welcome 1 times
Welcome 4 times
Welcome 5 times
Welcome 8 times
Welcome 9 times
Welcome 12 times
Welcome 13 times
Welcome 16 times
Welcome 17 times
Welcome 20 times
Welcome 21 times
Welcome 24 times
Welcome 25 times
Welcome 28 times
Welcome 29 times

Best regards.

On Sat, 2010-12-11 at 06:34 -0800, S Mathias 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
> $
> 
> 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:\
> 
> 


Reply to: