Bash: For Loop Range Example

{FIRST..LAST}

for i in {0..9}; do
  echo $i
done
$ for i in {0..9}; do echo $i; done
0
1
2
3
4
5
6
7
8
9

{FIRST..LAST..INCREMENT}

for i in {2..10..2}; do
  echo $i
done
$ for i in {2..10..2}; do echo $i; done
2
4
6
8
10

seq FIRST LAST

for i in $(seq 0 9); do
  echo $i
done
$ for i in $(seq 0 9); do echo $i; done
0
1
2
3
4
5
6
7
8
9

seq FIRST INCREMENT LAST vs. {FIRST..LAST..INCREMENT}

for i in $(seq 2 2 10); do
  echo $i
done
$ for i in $(seq 2 2 10); do echo $i; done
2
4
6
8
10

Leave a Comment

Your email address will not be published.

3 + 13 =