linux – Up Arrow的替代方案输入以运行上一个命令?
发布时间:2020-12-13 19:35:39 所属栏目:Linux 来源:网络整理
导读:有时我必须连续多次运行命令,例如查看服务是否已启动,将手移离正常输入位置以反复按向上箭头和输入键变得乏味.有没有办法在没有Up Arrow和Enter键的情况下运行上一个命令,可能还有一个精心设计的shell脚本? 我已经尝试了以下内容,但它不能令人满意,因为它无
有时我必须连续多次运行命令,例如查看服务是否已启动,将手移离正常输入位置以反复按向上箭头和输入键变得乏味.有没有办法在没有Up Arrow和Enter键的情况下运行上一个命令,可能还有一个精心设计的shell脚本? 我已经尝试了以下内容,但它不能令人满意,因为它无法执行别名,而且速度有点慢.
理想情况下,我有一个这个脚本的别名,所以我可以在命令行中键入类似“prev”的内容,然后按Enter键再次运行上一个命令. 最佳答案
在bash中:
$help fc fc: fc [-e ename] [-lnr] [first] [last] or fc -s [pat=rep] [command] Display or execute commands from the history list. fc is used to list or edit and re-execute commands from the history list. FIRST and LAST can be numbers specifying the range,or FIRST can be a string,which means the most recent command beginning with that string. Options: -e ENAME select which editor to use. Default is FCEDIT,then EDITOR,then vi -l list lines instead of editing -n omit line numbers when listing -r reverse the order of the lines (newest listed first) With the `fc -s [pat=rep ...] [command]' format,COMMAND is re-executed after the substitution OLD=NEW is performed. A useful alias to use with this is r='fc -s',so that typing `r cc' runs the last command beginning with `cc' and typing `r' re-executes the last command. Exit Status: Returns success or status of executed command; non-zero if an error occurs. 注意别名r的建议;我经常使用它. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |