bash sequence 00 01 ... 10

use seq command with -f parameter, try:

seq -f "%02g" 0 10

results: 00 01 02 03 04 05 06 07 08 09 10

seq -f "%03g" 0 10

results: 000 001 002 003 004 005 006 007 008 009 010


This will work in any shell on a machine that has coreutils installed (thanks commenters for correcting me):

seq -w 1 10

and

seq -w 1 100

Explanation:

  • the option -w will:

Equalize the widths of all numbers by padding with zeros as necessary.

  • seq [-w] [-f format] [-s string] [-t string] [first [incr]] last

prints a sequence of numbers, one per line (default), from first (default 1), to near last as possible, in increments of incr (default 1). When first is larger than last the default incr is -1

Tags:

Bash