How to use arguments from previous command?

前端 未结 11 1783
一个人的身影
一个人的身影 2020-12-04 04:35

I know that Esc + . gives you the last argument of the last command.

But I\'m interested in first argument of the last command. Is there a key

11条回答
  •  隐瞒了意图╮
    2020-12-04 05:08

    To use the first argument, you can use !^ or !:1

    Example:

    $ echo a b c d e 
    a b c d e
    $ echo !^
    echo a
    a
    
    $ echo a b c d e 
    a b c d e
    $ echo !:1
    echo a
    a
    

    Since your question is about using any other arguments, here are some useful ones:

    !^      first argument
    !$      last argument
    !*      all arguments
    !:2     second argument
    
    !:2-3   second to third arguments
    !:2-$   second to last arguments
    !:2*    second to last arguments
    !:2-    second to next to last arguments
    
    !:0     the command
    !!      repeat the previous line
    

    The first four forms are more often used. The form !:2- is somewhat counter-intuitive, as it doesn't include the last argument.

提交回复
热议问题