How to iterate through numbers in bash

This is part of the Semicolon&Sons Code Diary - consisting of lessons learned on the job. You're in the bash category.

Last Updated: 2023-03-28

Say you want to iterate all the numbers between 0 and 60 in bash. How would you do it?

Answer: The seq command. Here's an example:

for i in $(seq 0 60); do echo $i; done
# 0
# 1
# 2
# ...
# 60

Another possibility is this:

for i in {0..60}
  echo "Number: $i"