Communities for your favorite technologies. Explore all Collectives
Stack Overflow for Teams is now called Stack Internal. Bring the best of human thought and AI automation together at your work.
Bring the best of human thought and AI automation together at your work. Learn more
Find centralized, trusted content and collaborate around the technologies you use most.
Stack Internal
Knowledge at work
Bring the best of human thought and AI automation together at your work.
I was trying to print out some numbers from 1 to 20 with an increment of 2
#!/bin/bash for i in {0..20..2} do echo $i done
and this is what it has printed out
{0..20..2}
what I am doing wrong?
for
for ((i=0; i<=20; i+=2)); do echo $i; done
seq 0 2 20
seq
Using the built-in for loops syntax:
#!/bin/bash for (( i=0; c<=20; c+=2 )) do echo $i done
Add a comment
Required, but never shown
By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.
Start asking to get answers
Find the answer to your question by asking.
Explore related questions
See similar questions with these tags.
forloop:for ((i=0; i<=20; i+=2)); do echo $i; doneseq 0 2 20seqisn't part of bash and isn't specified by POSIX, so you pay external-executable startup costs, and whether it works (and how it works) is entirely at the grace of your operating system vendor.