将 !12 解释为字符串而不是终端历史记录

将 !12 解释为字符串而不是终端历史记录

在 curl 中使用下面的示例命令,它没有按预期工作:

curl -ik "http://localhost/index.php?username=parto&password=hello!23"

我期望传递的参数包括:

username = parto
password = hello!23

!23但密码中的部分被解释为历史事件指示符。如果第23条命令是sudo apt-get update,则命令变为:

curl -ik "http://localhost/index.php?username=parto&password=hellosudo apt-get update"

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

   >!      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 Modifiers below).
   !#     The entire command line typed so far.

如果不使用手册页(上面引用)中所示的额外字符,我们如何“告诉”终端不要将上面的命令(!23)解释为事件指示器?

答案1

没有办法在双引号中使用感叹号。使用反斜杠将其取消引号,或使用单引号代替双引号,因为特殊字符不会在单引号中展开。

curl -ik "http://localhost/index.php?username=parto&password=hello"\!"23"
curl -ik 'http://localhost/index.php?username=parto&password=hello!23'

相关内容