在 curl 请求时,终端在 & 符号 (&) 周围抛出错误

Terminal throwing error around ampersand (&) on curl request

我正在尝试使用 Mac 运行 Big Sur 上的终端和 zsh 作为我的 [=23] 对 public API 执行一个非常简单的 curl 请求=].这是命令:

https://api.nasa.gov/neo/rest/v1/feed?start_date=2021-11-11&end_date=2021-11-11&api_key=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

我不断收到此错误消息:

zsh: parse error near `&'

我不明白这是什么意思,因为命令中没有引号。我尝试将密钥用引号括起来,看看是否可以解决它,同样的消息,然后尝试将日期和密钥括起来,同样的事情,切换参数的顺序,相同。

在此方面如有任何帮助,我们将不胜感激。

你应该引用 "offending" 论点,因为它包含 shell 元字符

卷曲 https://www.google.com/search?q=test&ie=utf-8&oe=utf-8&client=firefox-b-ab

应该变成

卷曲“ https://www.google.com/search?q=test&ie=utf-8&oe=utf-8&client=firefox-b-ab"

您可以使用单引号或双引号,也可以转义(前缀为 blackslash) 只有 & 和 ?字符,因为它们都是 shell 元字符,像这样:

卷曲 https://www.google.com/search\?q=test\&ie=utf-8\&oe=utf-8\&client=firefox-b-ab

您可以在此处阅读有关 shell 元字符的更多信息:

http://faculty.salina.k-state.edu/tim/unix_sg/shell/metachar.html

希望对您有所帮助,此致