加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Linux > 正文

linux – 使用不同的参数重新运行上一个命令

发布时间:2020-12-14 01:07:08 所属栏目:Linux 来源:网络整理
导读:如果要重新运行具有相同参数的命令,可以执行以下操作: vim long_filenamecat !$ #same as 'cat long_filename' 这节省了在传递给cat时必须再次键入前一个参数. 但是,如何传递与上次运行脚本/命令不同的参数? long_annoying_script_name arg1 arg2? arg3 ar
如果要重新运行具有相同参数的命令,可以执行以下操作:

vim long_filename
cat !$                    #same as 'cat long_filename'

这节省了在传递给cat时必须再次键入前一个参数.

但是,如何传递与上次运行脚本/命令不同的参数?

long_annoying_script_name arg1 arg2
? arg3 arg4                                  #? signifies shortcut symbols such as '!$'

当然我可以按下“向上”箭头并删除参数并键入新的参数,但是有更短/更快的方式吗?

我不想分配别名.

解决方法

!:0应该做的伎俩.从zsh文档:

   Word Designators
       A word designator indicates which word or words of a given command line
       are to be included in a history reference.  A `:' usually separates the
       event specification from the word designator.  It may be  omitted  only
       if  the  word designator begins with a `^',`$',`*',`-' or `%'.  Word
       designators include:

       0      The first input word (command).
       n      The nth argument.
       ^      The first argument.  That is,1.
       $     The last argument.
       %      The word matched by (the most recent) ?str search.
       x-y    A range of words; x defaults to 0.
       *      All the arguments,or a null value if there are none.
       x*     Abbreviates `x-$'.
       x-     Like `x*' but omitting word $.

(它也适用于bash.)如果你发现输入更方便的话,还有! – 1.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读