seq — Print an arithmetic sequence of numbers, one per line across all 5 shells
Equivalents in every shell
seq 1 10Prints 1 through 10, one per line. 1-arg form: `seq 10` → 1..10. 3-arg form: `seq START STEP END` (e.g. `seq 0 2 20` → 0,2,4…20). `-s SEP` joins on a separator: `seq -s , 1 5` → `1,2,3,4,5`.
seq 1 10Same external binary. Zsh brace expansion is the no-fork alternative: `{1..10}` (printing) or `printf "%s\n" {1..10}` (line per number). Brace ranges support step: `{1..20..2}` → odd numbers.
seq 1 10Fish ships `seq` as a builtin (no external fork required). Same arg semantics as GNU `seq`. For brace-range-style use, fish supports `(seq 1 10)` inline.
1..10Pwsh range operator — generates the sequence as integers. For arbitrary step use `1..10 | Where-Object { $_ % 2 -eq 0 }` (filter) or `for ($i=0; $i -le 20; $i += 2) { $i }` (explicit step). `1..10 -join ","` produces a comma-separated string.
for /L %I in (1,1,10) do @echo %I`for /L %I in (START,STEP,END)` — note STEP is the second argument (different order from `seq`). `1,1,10` = 1 through 10 step 1. Reverse: `for /L %I in (10,-1,1) do @echo %I`.
Worked examples
Loop from 1 to N
for i in $(seq 1 5); do echo "Iteration $i"; donefor i in (seq 1 5); echo "Iteration $i"; end1..5 | ForEach-Object { "Iteration $_" }for /L %I in (1,1,5) do @echo Iteration %IGenerate zero-padded numbers (001, 002, … 010)
seq -w 1 10seq -w 1 101..10 | ForEach-Object { "{0:D3}" -f $_ }for /L %I in (1,1,10) do @set "n=00%I" & call echo %%n:~-3%%Generate a CSV row of values
seq -s , 1 5string join , (seq 1 5)(1..5) -join ","powershell -Command "(1..5) -join ','"Gotchas
- `seq` is NOT POSIX — BSD-derived systems (older macOS) included it but some minimalist distributions (BusyBox in default config) DO NOT. Portable scripts targeting Alpine should use `for i in $(seq 1 N)` only after verifying `command -v seq`; safer fallback uses bash brace expansion `for i in {1..N}`.
- Brace expansion `{1..10}` is BASH/ZSH only — POSIX `sh` (dash) does NOT support it. Inside `#!/bin/sh` scripts the brace stays literal: `for i in {1..10}` iterates ONCE with `i="{1..10}"`. Use `seq` or a `while` loop for `sh`.
- Mac BSD `seq` behaves slightly differently from GNU `seq` on edge cases: `seq 1.5` produces `1\n` (GNU) vs error (BSD). Stick to integer args for cross-OS portability or test on both.
- pwsh `1..1000000` allocates the full array in memory before piping. For huge ranges streamed lazily, use `for ($i=1; $i -le 1000000; $i++) { $i }` (loop) instead — `1..N` is fine up to ~10M but blows past memory beyond.
- cmd `for /L %I in (1,1,10)` uses ONE percent in scripts (`%I`) and TWO percents in commands (`%%I`). Copy-pasting from interactive prompt into a `.bat` file silently breaks — the loop body never runs because `%I` expands to literal `%I` at parse time.