#!/bin/bash
for i in $(seq 1 2 10)
do
echo "skip by 2 value $i"
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.
$ seq 4
1
2
3
4
$ seq 2 5
2
3
4
5
$ seq 4 2 12
4
6
8
10
12
$ seq -w 4 2 12
04
06
08
10
12
$ seq -s, 4 2 12
4,6,8,10,12
Pure Bash, without an extra process:
for (( COUNTER=0; COUNTER<=10; COUNTER+=2 )); do
echo $COUNTER
done
Source: Stackoverflow.com