bang-bang — History expansion `!!` — repeat the previous command across all 5 shells
Equivalents in every shell
!!Bang-bang expands at PARSE time to the previous command line, then bash re-prints and runs it. Common idiom: `sudo !!` reruns the last command with sudo. `history -p '!!'` shows what would expand without running. Disable history expansion entirely with `set +H` if `!` keeps biting you in passwords / URLs.
!!Same POSIX history-expansion grammar as bash; zsh also accepts the `r` builtin and `fc -e -` as fc-style alternatives. The `Esc-.` keystroke inserts the LAST argument inline (preview before running) — usually nicer than blind `!!`. Disable bang expansion with `setopt no_bang_hist` if it surprises you.
$history[1] | sourceFish dropped POSIX `!!` deliberately as of 3.0 — the modern UX is Up-arrow + Enter (with autosuggest history). For scripted re-run, `eval $history[1]` works but fires unconditionally. `bind \e\[A history-prefix-search-backward` gives prefix-aware history search.
Invoke-HistoryNo `!!` operator. `Invoke-History` (alias `r`) replays the LAST command from `Get-History`; `Invoke-History 7` replays history entry 7. PSReadLine's `Ctrl-R` does interactive reverse-i-search, the modern equivalent muscle-memory for bang-bang users.
F3cmd.exe has no bang expansion. Press `F3` to recall the entire last command, or `F8` for prefix-match scrolling backwards through doskey history. `doskey /history` lists the buffer; there is no scriptable in-line replay operator.
Worked examples
Re-run the previous command with sudo (the canonical bang-bang use)
sudo !!sudo !!sudo $history[1]Start-Process pwsh -Verb RunAs -ArgumentList "-c", (Get-History -Count 1).CommandLinePreview the expansion without executing (verify before damage)
history -p '!!'print -r -- !!:p(Get-History -Count 1).CommandLineReplay the last command unmodified
!!!!rF3Gotchas
- Bash history expansion fires inside DOUBLE-quoted strings too — `echo "Hello !!"` will substitute the previous command, breaking the literal. Single-quote or `\!` to escape. The single most common gotcha when pasting URLs / passwords containing `!` into bash.
- Bang expansion happens BEFORE `set -e` / safety guards take effect — a typo like `!ls` matching a destructive recent command (`!rm`) will run with no confirmation. The defensive habit is the `:p` modifier (`!!:p` — print-don't-execute) before committing to the dangerous form.
- In fish, `!!` is parsed as two literal `!` characters and ignored — you will silently get nothing instead of the previous command. The fish way is the Up-arrow autosuggestion or `$history[1]`. Bash muscle memory will quietly fail rather than error in fish.
- PowerShell `Get-History` is per-session by default — closing pwsh loses it. PSReadLine's `Get-PSReadLineOption | Select HistorySavePath` enables persistent history; the path is OS-specific (`%APPDATA%\Microsoft\Windows\PowerShell\PSReadLine\` on Windows, `~/.local/share/powershell/PSReadLine/` on Linux/macOS).
- cmd.exe `doskey` history dies with the cmd window. There is no on-disk persistence and no `!!` operator — keyboard-only recall via `F3`/`F7`/`F8`. Scripts cannot programmatically re-run "the last command" in cmd; this is one of the genuine gaps PowerShell was built to close.