history expansion
Interactive shortcuts starting with an exclamation mark that reuse earlier commands, such as a double exclamation mark for the whole previous line.
In more detail
!$ is the last word of the previous line and !grep is the most recent line starting with grep. It happens before quoting is applied, even inside double quotes, which is why an exclamation mark in a double-quoted string can surprise you. It is switched off in scripts; add :p to print an expansion without running it.
Examples
sudo !!!!:pRelated terms
- command history — The numbered list of commands you have typed, which bash keeps and saves to a file when the shell exits.
- interactive shell — A shell reading commands from you at a terminal, as opposed to a non-interactive shell running a script.
- double quotes — Quotes that keep text together as one word but still let dollar expansions and backticks work inside.
Taught in
- Help, History, Completion And Aliases — Bash Scripting & Command Line Automation
- Shebangs, Permissions And Three Ways To Run — Bash Scripting & Command Line Automation