From 03819122c9bc668750cd8c9a7f8a4a92c615c0e3 Mon Sep 17 00:00:00 2001 From: marchersimon <50295997+marchersimon@users.noreply.github.com> Date: Sun, 4 Apr 2021 22:07:13 +0200 Subject: [PATCH] histexpand: add page (#5455) Also add a reference to the new page in bash.md and zsh.md --- pages/common/bash.md | 4 ++-- pages/common/histexpand.md | 36 ++++++++++++++++++++++++++++++++++++ pages/common/zsh.md | 4 ++-- 3 files changed, 40 insertions(+), 4 deletions(-) create mode 100644 pages/common/histexpand.md diff --git a/pages/common/bash.md b/pages/common/bash.md index 6822e8e9f..86baad965 100644 --- a/pages/common/bash.md +++ b/pages/common/bash.md @@ -1,7 +1,7 @@ # bash -> Bourne-Again SHell. -> `sh`-compatible command line interpreter. +> Bourne-Again SHell, an `sh`-compatible command line interpreter. +> See also `histexpand` for history expansion. > More information: . - Start interactive shell: diff --git a/pages/common/histexpand.md b/pages/common/histexpand.md new file mode 100644 index 000000000..ddb6f743a --- /dev/null +++ b/pages/common/histexpand.md @@ -0,0 +1,36 @@ +# history expansion + +> Reuse and expand the shell history in bash or zsh. +> More information: . + +- Run the previous command: + +`!!` + +- Run the previous command as root: + +`sudo !!` + +- Run a command with the last argument of the previous command: + +`{{command}} !$` + +- Run a command with the first argument of the previous command: + +`{{command}} !^` + +- Run the command `n` lines back in the history: + +`!-{{n}}` + +- Run the most recent command starting with `string`: + +`!{{string}}` + +- Run the previous command, replacing `string1` with `string2`: + +`^{{string1}}^{{string2}}^` + +- Perform a history expansion, but print the command that would be run instead of actually running it: + +`{{!-n}}:p` diff --git a/pages/common/zsh.md b/pages/common/zsh.md index d036e06b1..049999939 100644 --- a/pages/common/zsh.md +++ b/pages/common/zsh.md @@ -1,7 +1,7 @@ # zsh -> Z SHell. -> `bash` and `sh`-compatible command line interpreter. +> Z SHell, a `bash` and `sh`-compatible command line interpreter. +> See also `histexpand` for history expansion. > More information: . - Start interactive command line interpreter: