Nono.MA

For loop in bash

DECEMBER 28, 2022

Iterating through a list.

for i in 1 2 3
do
  echo $i
done
# 1
# 2
# 3

Iterating through a list generated with a sequence.

for i in $(seq 1 2 10)
do
  echo $i
done
# 1
# 3
# 5
# 7
# 9

seq 1 2 10 creates a list of numbers from 1 to 10 in steps of 2.

BlogCodeBash