Skip to content
Advertisement

How to add more than 1 number in a loop in Bash script?

So I have this loop:

for ((i=100;i<1001;i++));
do
     echo $i
     sleep 1
done

I want to know how I can add 10 every time the loop repeats instead of adding 1. So I want the loop to look something like this: 110 120 130 140 and keep going until it reaches the limit or stopped! Thanks

Advertisement

Answer

for ((i=100;i<1001;i+=10));
do
     echo $i
     sleep 1
done

Simply change ++ to += 10

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement