【问题标题】:curl replaces double quotes to single quote in bashcurl在bash中将双引号替换为单引号
【发布时间】:2020-12-28 20:27:44
【问题描述】:

我有这个变量

TOKEN="Authorization: Bearer eyJ0eXA"

当我将它添加到命令 curl 时

curl  -H "$TOKEN"  GET 'https://x.x.x.x/service/' --header 'Accept-Language: en' 

运行时,将-H后的"替换为',使命令像

curl -H 'Authorization: Bearer eyJ0eXA' GET https://x.x.x.x/service/ --header 'Accept-Language: en' 

如何避免这种情况并让命令以 "

运行

【问题讨论】:

    标签: linux bash variables curl


    【解决方案1】:

    没有要替换的引号。它们已被 shell 移除:

    TOKEN="Authorization: Bearer eyJ0eXA"
    echo $TOKEN
    Authorization: Bearer eyJ0eXA
    

    如果您想在字符串周围加上双引号,请更改为:

    TOKEN='"Authorization: Bearer eyJ0eXA"'
    echo $TOKEN
    "Authorization: Bearer eyJ0eXA"
    

    【讨论】:

      【解决方案2】:

      我猜你看到的是set -x 或其他shell 调试的结果。

      在这种情况下,它是完全正确的。 $TOKEN 已被评估并替换为它的值。单引号向 shell 表明不会对该值进行进一步处理。它们既不会被curl 看到,也不会传递给目标主机。

      【讨论】:

        猜你喜欢
        • 2017-06-19
        • 2018-11-18
        • 1970-01-01
        • 2017-12-29
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-08-01
        相关资源
        最近更新 更多