我正在使用 Ubuntu,我想重复我执行过的一系列命令。我试过类似的东西
for i in $(seq 2006 2013); do \!$i; done;
但失败了,因为 shell 试图执行命令 '!2006'。
man history
也没有告诉我如何重复一系列命令。
最佳答案
如果您正在使用 bash
(或 ksh
),fc
内置允许您以各种方式操纵历史记录。
fc -l # list recent history.
fc -l 2006 2013 # list commands 2006..2013
fc 2006 2013 # launch editor with commands 2006..2013; executes what you save
fc -e pico 2006 2013 # launches the editor pico on command 2006..2013
fc -e - 2006 2013 # Suppresses the 'edit' phase (but only executes the first listed command)
fc -e : 2006 2013 # Launches the ':' command (a shell built-in) as the editor
ksh
中的经典技术是使用别名 alias r='fc -e -'
,但是由于 bash
的行为>,有必要稍微用力扭动它的 ARM 并使用 alias r='fc -e :'
代替。
关于linux - 执行一系列历史命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24699369/