【问题标题】:Why cURL outputs process name? And how to get rid of it? [duplicate]为什么 cURL 输出进程名称?以及如何摆脱它? [复制]
【发布时间】:2016-11-11 16:48:57
【问题描述】:

通常当您使用 cURL 时,输出如下所示:

alex$ curl http://some-url
some-content

但是,对于某些 url,输出是不同的:

alex$ curl http://some-url
[1] 81030
alex$ some-content
[1]+  Done                    curl http://some-url

为什么会发生这种情况以及如何摆脱它并使 cURL 只输出内容?

【问题讨论】:

    标签: bash curl


    【解决方案1】:

    如果 some-url 包含 & 字符,则 shell 将其解释为在后台运行进程的命令。

    要克服它,可以使用 \& 转义 &(添加反斜杠)。

    【讨论】:

      【解决方案2】:

      Kevin's answer 很有帮助,Kevin 在没有具体信息的情况下推断出您的具体问题值得称赞。

      让我补充一下一般性建议:

      而不是单独通过\前缀转义shell元字符(对shell具有特殊意义的字符),考虑:

      • 文字括在引号中;例如:curl 'http://example.org/search&query=foo'

      • 变量引用括在引号中;例如:url='http://example.org/search&query=foo'; curl "$url"

      这样您就不必担心要转义哪些单个字符。

      一般来说,只有在你明确想要 shell 来解释它们(通过应用所谓的@ 987654322@).

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-02-02
        • 2022-08-18
        • 2014-07-14
        • 2012-01-27
        • 2021-04-03
        • 2017-12-04
        相关资源
        最近更新 更多