sleep — Pause shell execution for a fixed duration across all 5 shells
Equivalents in every shell
sleep 5GNU coreutils `sleep` accepts integer seconds OR a suffix: `5s`, `5m`, `5h`, `5d`. Fractional seconds: `sleep 0.5`. Multiple args sum: `sleep 1m 30s` = 90s. BusyBox / Alpine `sleep` accepts ONLY integer seconds (no suffix, no fraction) — a common surprise in containers.
sleep 5Same external binary as bash. Zsh ships a `zselect` builtin (`zselect -t 50` waits 50 centiseconds) for sub-second pauses without forking an `/bin/sleep` process — useful inside tight scripting loops.
sleep 5External `/bin/sleep` — same syntax and limitations as bash. Fish has no builtin equivalent; for sub-second pauses inside a fish script, `sleep 0.5` works on GNU but not BusyBox.
Start-Sleep -Seconds 5Aliased as `sleep`. Use `-Milliseconds 500` for sub-second pauses (the `-Seconds` parameter is `[int]`, no fractional support). Pwsh 6+ also accepts `[TimeSpan]`: `Start-Sleep -Duration ([TimeSpan]::FromMinutes(2))`. Ctrl-C interrupts cleanly — the `Start-Sleep` returns via `OperationCanceledException`.
timeout /t 5 /nobreak`timeout /t 5` (without `/nobreak`) aborts on ANY keypress — fine for prompts, not for unattended scripts. `/nobreak` blocks the abort, only `Ctrl-Break` interrupts. There is no `sleep.exe` shipped with Windows; the older `ping -n 6 127.0.0.1 >NUL` hack still works (`-n N` does N pings 1s apart, so pings minus 1 = effective seconds).
Worked examples
Sleep for 500 milliseconds
sleep 0.5sleep 0.5Start-Sleep -Milliseconds 500timeout /t 1 /nobreak >NULPoll a URL every 5 seconds until it returns 200
while ! curl -fs http://app/health; do sleep 5; donewhile not curl -fs http://app/health; sleep 5; endwhile ($true) { try { Invoke-RestMethod http://app/health; break } catch { Start-Sleep -Seconds 5 } }:loop\r\ncurl -fs http://app/health || (timeout /t 5 /nobreak >NUL & goto loop)Wait 2 minutes before retrying
sleep 2msleep 2mStart-Sleep -Seconds 120timeout /t 120 /nobreak >NULGotchas
- BusyBox `sleep` (Alpine, embedded Linux, many Docker images) accepts ONLY integer seconds — `sleep 0.5` errors with `sleep: invalid number \'0.5\'`. If your image is `alpine:3`, every sub-second wait needs a workaround like `sleep 1` rounded up, or installing `coreutils`.
- `Start-Sleep -Seconds 0.5` does NOT error — pwsh silently floors to 0 (the parameter is `[int]`). The bug: a script meant to retry every 500ms instead retries with no delay, hammering the endpoint. Always use `-Milliseconds 500` for sub-second pauses.
- cmd `timeout /t N` without `/nobreak` is interactive — pressing any key aborts. A `for` loop with `timeout` inside `for /l %i in (1,1,10) do timeout /t 60` lets ANY keypress short-circuit the entire batch. Always pair `/t` with `/nobreak` in scripts.
- `timeout /t 5` only works in a real cmd console — under SSH, in Jenkins agents, or in MSYS terminals, `timeout` errors with `ERROR: Input redirection is not supported, exiting the process immediately.` Workaround: `ping -n 6 127.0.0.1 >NUL` (no terminal dependency), or detect interactive shell first.
- Inside `while true; do work; sleep 1; done`, the `sleep` runs as a separate process — Ctrl-C kills the `sleep` and the loop continues to the next iteration's `work`. To make the WHOLE loop interruptible, trap SIGINT: `trap "exit 0" INT; while true; ...`. Same wart applies to pwsh — Ctrl-C in `while ($true) { Start-Sleep 1 }` only kills the current Start-Sleep call.
WSL & PowerShell Core notes
Common tasks using sleep
- Retry a command on failure
Re-run a command until it succeeds or a retry cap is hit — useful for flaky network calls and CI race conditions.
- Run a command at a specific time
Schedule a one-shot command to run at a given clock time — `at` on Unix, Task Scheduler on Windows.
- Run a command every N seconds
Repeat a command on a fixed-interval polling loop — useful for live dashboards, healthcheck-watching, and tail-style log monitoring.
- Run a command with a timeout
Kill a command if it has not finished within N seconds — the standard hedge against hung network calls, runaway scripts, and tests that should never block forever.
- Wait for a process to finish
Block until a given process exits — useful for sequencing, dependency-management scripts, and orchestrated shutdowns.