bash 中的 unix 历史命令“!$”是什么?

What is the unix history command "!$" in bash?

我正在尝试了解什么是 unix 命令 !$

比如我知道命令!1用于运行历史命令编号1.

似乎 !$ 运行 是 bash 中输入的最后一个命令。

例如,如果我写 mv folder12 folder123 然后我会写 cd !$ 我实际上会预制 cd folder123.

!$ 运行 是 bash 中输入的最后一个命令是否正确?

!$ 匹配前一个命令的最后一个参数。

来自man bash

yank-last-arg (M-., M-_)

Insert the last argument to the previous command (the last word of the previous history entry). With an argument, behave exactly like yank-nth-arg. Successive calls to yank-last-arg move back through the history list, inserting the last argument of each line in turn. The history expansion facilities are used to extract the last argument, as if the "!$" history expansion had been specified.

例子

$ vi a
$ ls -l !$ # expands to "ls -l a"
-rw-rw-r-- 1 me me 30 18 abr.  22:00 a

另见 What is your single most favorite command-line trick using Bash?:

I'm a fan of the !$, !^ and !* expandos, returning, from the most recent submitted command line: the last item, first non-command item, and all non-command items. To wit (Note that the shell prints out the command first).

还有一本好书:The Definitive Guide to Bash Command Line History