Tools: Complete Guide to Pause Scripts with 'Press Any Key' in Bash, CMD, PowerShell, and macOS

Tools: Complete Guide to Pause Scripts with 'Press Any Key' in Bash, CMD, PowerShell, and macOS

When to pause (and when not to)

Windows CMD

PowerShell

Wait for Enter only

Wait for any key (Windows console)

Bash (Linux and macOS)

macOS notes

POSIX sh (portable “press Enter”)

Cross-platform branching

Related reading

Useful links Batch files and shell scripts often need a short wait so a double-clicked window or installer log stays visible. Windows CMD has a dedicated pause command. Unix shells use read. PowerShell sits in the middle and needs an explicit pattern. This page collects portable snippets and the usual pitfalls (pipes, SSH without TTY, CI). For more shell references, see the Bash cheat sheet and PowerShell cheatsheet. For broader tooling workflows, visit Developer Tools: The Complete Guide to Modern Development Workflows. Use a pause when a human is watching an interactive terminal and you want to avoid an instant exit—for example after a .bat file is double-clicked, or after a local maintenance script prints a summary. Skip pauses in cron, systemd services, CI pipelines, and most SSH one-liners. There is often no keyboard attached and stdin may not be a terminal, so waiting for input can hang forever. In Bash and POSIX sh, test with [ -t 0 ] (or test -t 0) before prompting. The pause command prints a localized line such as “Press any key to continue . . .” and waits for a keypress. If output is redirected, behavior can differ; for scripts that must run logged to a file, consider timeout /t N for a timed delay instead of an interactive pause. choice is useful when you want a timed wait or specific keys (menu scripts). It is a separate topic from pause but often appears in the same batch workflows. PowerShell has no single pause alias that matches CMD in every host. Two common patterns follow. Simple and works in many hosts including some IDEs. This is not “any key”—only Enter counts. In Windows PowerShell running in a normal console host, ReadKey waits for a physical key: If $Host.UI or RawUI is not available (some non-interactive hosts, remoting, or constrained environments), this can fail. Wrap such calls in try / catch or detect [Console]::KeyAvailable / host capabilities when you need robustness. PowerShell 7 on non-Windows platforms may not offer the same ReadKey experience; prefer Read-Host or shell-native read in those cases. Classic “any key” style with a visible prompt and no echo of the key: With a friendly guard for automation: Terminal.app and iTerm2 behave like other Unix terminals for Bash. Apple’s default login shell is often Zsh; for interactive Zsh you may use read -k 1 in scripts explicitly run by Zsh. For maximum portability across Linux and macOS, stay with Bash or document #!/usr/bin/env bash at the top of the script. POSIX read does not require read -n, which is not POSIX. The portable pattern is “press Enter to continue”: That is widely supported on dash, ksh, and ash-based systems. True single-character “any key” without Bash extensions is messier; if you need it on minimal sh, document Bash or use stty-based approaches with care (terminal state, portability). Installer scripts sometimes branch on OS: In mixed environments, keep the “interactive only” guard so servers and CI never block. Templates let you quickly answer FAQs or store snippets for re-use. Hide child comments as well For further actions, you may consider blocking this person and/or reporting abuse

Code Block

Copy

:: save as pause-demo.bat @echo off echo Hello from CMD pause :: save as pause-demo.bat @echo off echo Hello from CMD pause :: save as pause-demo.bat @echo off echo Hello from CMD pause # pause-demo.ps1 Read-Host 'Press Enter to continue' # pause-demo.ps1 Read-Host 'Press Enter to continue' # pause-demo.ps1 Read-Host 'Press Enter to continue' # pause-any-key.ps1 Write-Host 'Press any key to continue...' $null = $Host.UI.RawUI.ReadKey('NoEcho,IncludeKeyDown') # pause-any-key.ps1 Write-Host 'Press any key to continue...' $null = $Host.UI.RawUI.ReadKey('NoEcho,IncludeKeyDown') # pause-any-key.ps1 Write-Host 'Press any key to continue...' $null = $Host.UI.RawUI.ReadKey('NoEcho,IncludeKeyDown') #!/usr/bin/env bash read -r -n 1 -s -p $'Press any key to continue...\n' #!/usr/bin/env bash read -r -n 1 -s -p $'Press any key to continue...\n' #!/usr/bin/env bash read -r -n 1 -s -p $'Press any key to continue...\n' #!/usr/bin/env bash if [ -t 0 ]; then read -r -n 1 -s -p $'Press any key to continue...\n' fi #!/usr/bin/env bash if [ -t 0 ]; then read -r -n 1 -s -p $'Press any key to continue...\n' fi #!/usr/bin/env bash if [ -t 0 ]; then read -r -n 1 -s -p $'Press any key to continue...\n' fi #!/bin/sh printf 'Press Enter to continue... ' read -r _ #!/bin/sh printf 'Press Enter to continue... ' read -r _ #!/bin/sh printf 'Press Enter to continue... ' read -r _ - -n 1 — read one character - -s — silent (no echo) - -r — raw (backslash not special) - -p — prompt string - Windows CMD — pause - PowerShell — ReadKey or Read-Host - Unix — read with [ -t 0 ] guard - Bash cheat sheet — general command reference - PowerShell cheatsheet — cmdlets and everyday usage - GNU Bash manual — Bash Builtins — read - Microsoft Learn — Read-Host and console APIs for advanced hosts