How can I recall the argument of the previous bash command?

前端 未结 7 2007
轮回少年
轮回少年 2020-12-04 04:33

Is there a way in Bash to recall the argument of the previous command?

I usually do vi file.c followed by gcc file.c.

Is there a w

7条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-04 04:51

    If the previous command had two arguments, like this

    ls a.txt b.txt
    

    and you wanted the first one, you could type

    !:1
    

    giving

    a.txt
    

    Or if you wanted both, you could type

    !:1-2
    

    giving

    a.txt b.txt
    

    You can extend this to any number of arguments, eg:

    !:10-12
    

提交回复
热议问题