Skip to content
shellmap

seqPrint an arithmetic sequence of numbers, one per line across all 5 shells

Equivalents in every shell

Bashunix
seq 1 10

Prints 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`.

Zshunix
seq 1 10

Same 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.

Fishunix
seq 1 10

Fish 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.

PowerShellwindows
1..10

Pwsh 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.

cmd.exewindows
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

Bash
for i in $(seq 1 5); do echo "Iteration $i"; done
Fish
for i in (seq 1 5); echo "Iteration $i"; end
PowerShell
1..5 | ForEach-Object { "Iteration $_" }
cmd.exe
for /L %I in (1,1,5) do @echo Iteration %I

Generate zero-padded numbers (001, 002, … 010)

Bash
seq -w 1 10
Fish
seq -w 1 10
PowerShell
1..10 | ForEach-Object { "{0:D3}" -f $_ }
cmd.exe
for /L %I in (1,1,10) do @set "n=00%I" & call echo %%n:~-3%%

Generate a CSV row of values

Bash
seq -s , 1 5
Fish
string join , (seq 1 5)
PowerShell
(1..5) -join ","
cmd.exe
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.

WSL & PowerShell Core notes

pwshpwsh `1..N` is the cleanest cross-OS sequence generator — no fork, no external binary, identical on Windows/Linux/macOS. For step ≠ 1 use `0..(($end - $start)/$step) | ForEach-Object { $start + $_ * $step }` or just an explicit `for` loop. Range up to `[int]::MaxValue` (~2.1B); beyond that switch to `[long]` or `[bigint]` math.
WSLWSL `seq` is GNU coreutils — identical to Linux. Useful when calling from a Windows batch script that needs proper float-step support (`wsl seq 0 0.1 1` works; cmd `for /L` is integer-only).

Related commands