我正在尝试使用 curl 命令访问!路径中带有感叹号 ( )的 http url 。例如:
curl -v "http://example.org/!287s87asdjh2/somepath/someresource"
Run Code Online (Sandbox Code Playgroud)
控制台回复bash: ... event not found.
这里发生了什么?逃避感叹号的正确语法是什么?
我用了
history | less
Run Code Online (Sandbox Code Playgroud)
为了获取先前命令的行和左侧的数字,我找到了我想要重复的行(例如 22)并做了
!22
Run Code Online (Sandbox Code Playgroud)
在命令提示符下,它起作用了——在我当时所做的行上执行命令集。我无法弄清楚感叹号在哪里使用,它在 bash 采取的操作方面代表什么,以及在哪里使用它。从文档中我没有看到“有形”的解释。
我意识到这!在命令行历史上下文中对命令行具有特殊意义,但除此之外,在运行脚本中,感叹号有时会导致解析错误。
我认为它与 an 有关event,但我不知道事件是什么或它做什么。即便如此,相同的命令在不同情况下的行为也会有所不同。
下面的最后一个示例导致错误;但是为什么,当相同的代码在命令替换之外工作时呢?.. 使用 GNU bash 4.1.5
# This works, with or without a space between ! and p
{ echo -e "foo\nbar" | sed -nre '/foo/! p'
echo -e "foo\nbar" | sed -nre '/foo/!p'; }
# bar
# bar
# This works, works when there is a space between ! and p
var="$(echo -e "foo\nbar" | sed -nre '/foo/! p')"; echo "$var"
# bar
# This causes an ERROR, with NO …Run Code Online (Sandbox Code Playgroud)