0

I create a sequence with interval 1 using {0..4} syntax alright:

$ for i in {0..4}; do echo $i; done 0 1 2 3 4 

However, when I set interval explicitly at 2 using conventional syntax {0..4..2}, it doesn't work:

$ for i in {0..4..2}; do echo $i; done {0..4..2} 

And the expected output should be:

0 2 4 

My bash version:

$ echo ${BASH_VERSION} 3.2.25(1)-release 

Any feedback is appreciated!

2 Answers 2

1

You could use the syntax:

$ for ((i=0; i<=4; i+=2)); do echo $i; done 
Sign up to request clarification or add additional context in comments.

Comments

0
$ for i in `seq 0 2 4`; do echo $i; done 

2 Comments

Nice and simple. Thank you! ...Still wondering why {0..4..2} is not working.
@koch No problem! From what I know, that curly brace step syntax only works in zsh, ksh93, and I believe bash 4+.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.