历史命令 !# 的作用是什么?

use*_*828 5 bash man command-history

从手册页history

\n\n
\n

事件指示符\n 事件指示符是对历史列表中命令行条目的引用。除非引用是绝对的,否则事件是相对于历史列表中的当前位置的。

\n
\n\n
   !      Start a history substitution, except when followed by  a  blank,\n          newline, = or (.\n   !n     Refer to command line n.\n   !-n    Refer to the current command minus n.\n   !!     Refer to the previous command.  This is a synonym for `!-1\'.\n   !string\n          Refer  to the most recent command preceding the current position\n          in the history list starting with string.\n   !?string[?]\n          Refer to the most recent command preceding the current  position\n          in  the  history  list containing string.  The trailing ? may be\n          omitted if string is followed immediately by a newline.\n   ^string1^string2^\n          Quick substitution.  Repeat the last command, replacing  string1\n          with string2.  Equivalent to ``!!:s/string1/string2/\'\' (see Mod\xe2\x80\x90\n          ifiers below).\n   !#     The entire command line typed so far.\n
Run Code Online (Sandbox Code Playgroud)\n\n

所有其他的都有道理,但我无法!#从上下文中找出任何用法。它有什么作用以及通常如何使用?

\n

cra*_*jun 1

在这里回答:!#:3 在 shell 命令中意味着什么

基本上,您可以使用它与 ':n' 组合来缩短命令,因此:

$ cd /home/me/some/super/deep/dir/that/i/do/not/want/to/type/again ; ll !#:2 
Run Code Online (Sandbox Code Playgroud)

当然,这是一个有点愚蠢的例子,因为你可以这样做ll,但你明白了,它可以在 sh 脚本中使用。