从手册页history
:
事件指示符 事件指示符是对历史列表中命令行条目的引用。除非引用是绝对的,否则事件是相对于历史列表中的当前位置的。
! Start a history substitution, except when followed by a blank,
newline, = or (.
!n Refer to command line n.
!-n Refer to the current command minus n.
!! Refer to the previous command. This is a synonym for `!-1'.
!string
Refer to the most recent command preceding the current position
in the history list starting with string.
!?string[?]
Refer to the most recent command preceding the current position
in the history list containing string. The trailing ? may be
omitted if string is followed immediately by a newline.
^string1^string2^
Quick substitution. Repeat the last command, replacing string1
with string2. Equivalent to ``!!:s/string1/string2/'' (see Mod‐
ifiers below).
!# The entire command line typed so far.
所有其他都有道理,但我无法!#
从上下文中找出任何用法。它有什么作用以及通常如何使用?
答案1
在这里回答:!#:3 在 shell 命令中的含义是什么
基本上,您可以使用它与 ':n' 组合来缩短命令,因此:
$ cd /home/me/some/super/deep/dir/that/i/do/not/want/to/type/again ; ll !#:2
当然,这是一个有点愚蠢的例子,因为你可以这样做ll
,但你明白了,它可以在 sh 脚本中使用。