HowTo: Generate and Print a Sequences of Numbers with BASH

You don’t have to type a range of numbers by hands!

BASH already has a built-in utility, named seq, for generating and printing a sequence of numbers.

Generate a sequence of numbers

Syntax: seq [OPTION]… FIRST
Syntax: seq [OPTION]… FIRST LAST

Print a sequence of numbers from 1 to 10:

$ seq 1 5
1
2
3
4
5

Generate a sequence of numbers with increment

Syntax: seq [OPTION]… FIRST INCREMENT LAST

Print a sequence of numbers from 0 to 20 with increment 5:

$ seq 0 5 20
0
5
10
15
20

Equalize width by padding with leading zeroes

Syntax: seq -w…

Equalize width by padding with leading zeroes:

$ seq -w 1 10
01
02
03
04
05
06
07
08
09
10

Use another separator

Syntax: seq -s SEPARATOR… – use SEPARATOR to separate numbers.

Default separator is a new line – "\n".

Use space to separate numbers:

$ seq -s " " 1 10
1 2 3 4 5 6 7 8 9 10