简体   繁体   English

curl 在 bash 中将双引号替换为单引号

[英]curl replaces double quotes to single quote in bash

I have this variable我有这个变量

TOKEN="Authorization: Bearer eyJ0eXA"

when I add it to command curl当我将它添加到命令 curl 时

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

when running, it replaces the " after -H to ' to make the command like运行时,它将 -H 后的"替换为'以使命令类似于

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

How to avoid that and make the command runs with "如何避免这种情况并使命令以

I would guess that what you are seeing is the result of set -x or some other shell debug.我猜你看到的是set -x或其他一些 shell 调试的结果。

In this case it's perfectly correct.在这种情况下,它是完全正确的。 The $TOKEN has been evaluated and replaced with its value. $TOKEN已被评估并替换为其价值。 The single quotes indicate to the shell that there is to be no further processing of the value.单引号向 shell 表明不对值进行进一步处理。 They are neither seen by curl nor passed on to the target host.它们既不会被curl看到,也不会传递给目标主机。

There are no quotes to replace.没有要替换的引号。 They are already removed by the shell:它们已经被 shell 删除了:

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

If you would like to have double quotes around your string then change to:如果您想在字符串周围加上双引号,请更改为:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM