gpt4 book ai didi

linux - bash 中的 unix 历史命令 "!$"是什么?

转载 作者:太空狗 更新时间:2023-10-29 11:37:04 25 4
gpt4 key购买 nike

我想了解什么是 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 .

关于linux - bash 中的 unix 历史命令 "!$"是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29756348/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com