Kev*_*rry 9 command-line bash history
如何在不执行的情况下按编号从历史记录中获取命令到我的命令行?
This immediately executes command number 555 which I'm not looking for:
$ history 10
$ !555
This opens the command up in an editor, which is overkill most of the time:
$ history 10
$ fc 555
This is an example of what I'm looking for:
$ history 10
$ #555
$ [command 555 from history listing now sitting here on my command line ready to edit or execute]
Run Code Online (Sandbox Code Playgroud)
谢谢!
bac*_*c0n 15
shopt -s histverify
Run Code Online (Sandbox Code Playgroud)
如果启用了 histverify shell 选项,并且正在使用 Readline,则历史替换不会立即传递给 shell 解析器。相反,扩展的行被重新加载到 Readline 编辑缓冲区中以进行进一步修改。
Rin*_*ind 11
:p在数字后添加。
例子:
1357 locate pam_loginuid
1358 history
rinzwind@discworld:~$ !1358:p
history
rinzwind@discworld:~$ !1357:p
locate pam_loginuid
rinzwind@discworld:~$
Run Code Online (Sandbox Code Playgroud)
打印显示而不执行。
要在 BASH 中使用它,您需要做更多的事情。示例:https :
//tldp.org/LDP/abs/html/histcommands.html
#!/bin/bash
set -o history
var=$(history); echo "$var" # 1 var=$(history)`
Run Code Online (Sandbox Code Playgroud)
会将所有历史记录放入 var 中,您需要更多逻辑来找到所需的命令。
如果您正在使用bash,我认为您是;输入历史编号:
$ !555
Run Code Online (Sandbox Code Playgroud)
然后按:Ctrl+ Alt+ e,现在历史记录中所需的命令位于您的提示中,等待执行而不更改历史记录的默认行为:
$ command
Run Code Online (Sandbox Code Playgroud)
这同样适用于aliases,substitutions,expansions和历史上说的论据:$ echo !555:1,~,$HOME,$(echo hi)。
这就是我如何确保在实际运行之前准确地执行历史记录中的哪个命令。