The way to iterate over a range in bash is
for i in {0..10}; do echo $i; done
What would be the syntax for iterating over the sequence with a step? Say, I would like to get only even number in the above example.
The way to iterate over a range in bash is
for i in {0..10}; do echo $i; done
What would be the syntax for iterating over the sequence with a step? Say, I would like to get only even number in the above example.
I'd do
for i in `seq 0 2 10`; do echo $i; done
(though of course seq 0 2 10
will produce the same output on its own).
Pure Bash, without an extra process:
for (( COUNTER=0; COUNTER<=10; COUNTER+=2 )); do
echo $COUNTER
done
Bash 4's brace expansion has a step feature:
for {0..10..2}; do
..
done
No matter if Bash 2/3 (C-style for loop, see answers above) or Bash 4, I would prefer anything over the 'seq' command.