seq: Generate Number Sequences for CI Loops
seq FIRST LAST prints the integers from FIRST to LAST, one per line, for driving loops.
Retry loops, shard indices, and generated fixtures all need a number range. seq produces one, with padding and formatting for stable output.
What it does
seq prints an arithmetic sequence. With one argument it counts 1..N; with two it counts FIRST..LAST; with three the middle value is the step. -w zero-pads to equal width and -s sets the separator. Part of coreutils.
Common usage
# retry a flaky step up to 3 times
for i in $(seq 1 3); do ./flaky.sh && break; done
# zero-padded shard ids: 01 02 ... 10
seq -w 1 10
# step by 2
seq 0 2 10
# comma-separated on one line
seq -s , 1 5 # 1,2,3,4,5Options
| Flag | What it does |
|---|---|
| FIRST LAST | Range endpoints (inclusive) |
| FIRST STEP LAST | Range with an explicit step |
| -w | Equal-width, zero-padded output |
| -s <str> | Separator between numbers (default newline) |
| -f <fmt> | printf-style format for each number |
In CI
Prefer for i in $(seq 1 "$N") over brace expansion {1..$N} in loops where N is a variable: brace expansion does not expand variables in POSIX sh and silently iterates the literal string. seq reads N at runtime, so the loop count is correct.
Common errors in CI
"seq: command not found" is rare (coreutils is nearly always present) but happens on ultra-minimal images. "seq: invalid floating point argument" means a non-numeric argument. A backwards range like seq 5 1 prints nothing (no error), which can make a loop body never run; use a negative step seq 5 -1 1 to count down.