有时我必须连续多次运行命令,例如查看服务是否已启动,将手移离正常输入位置以反复按向上箭头和输入键变得乏味.有没有办法在没有Up Arrow和Enter键的情况下运行上一个命令,可能还有一个精心设计的shell脚本?
我已经尝试了以下内容,但它不能令人满意,因为它无法执行别名,而且速度有点慢.
history | tail -2 | head -1 | cut -d' ' -f4- | cat > prev_command.txtsleep .01chmod 777 prev_command.txteval prev_command.txtrm prev_command.txt
理想情况下,我有一个这个脚本的别名,所以我可以在命令行中键入类似“prev”的内容,然后按Enter键再次运行上一个命令.最佳答案在bash中:
$help fcfc: 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的建议;我经常使用它. 总结
以上是内存溢出为你收集整理的linux – Up Arrow的替代方案输入以运行上一个命令?全部内容,希望文章能够帮你解决linux – Up Arrow的替代方案输入以运行上一个命令?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)