[英]What does the $'{}' mean in curl command
I am wondering what does the $ mean in the curl command when I am sending a POST. 我想知道当我发送POST时curl命令中的$是什么意思。
eg curl -X POST mydomain.com -d $'{\\n"some.*.something": "myvalue"\\n}'
例如
curl -X POST mydomain.com -d $'{\\n"some.*.something": "myvalue"\\n}'
Also I am trying to parameterized the myvalue
in my shell script, however I am unable to do it. 此外,我试图在我的shell脚本中参数化
myvalue
,但是我无法做到。 Any suggestions? 有什么建议?
The $'{\\n"some.*.something": "myvalue"\\n}'
gets interpreted by the shell before it gets passed to curl. 在将shell传递给curl之前,shell会解释
$'{\\n"some.*.something": "myvalue"\\n}'
。
$'...'
are so called ANSI C strings . $'...'
是所谓的ANSI C字符串 。 They exist in the shell language next to double-quoted strings "..."
and single-quoted strings '...'
. 它们以双引号字符串
"..."
和单引号字符串 '...'
旁边的shell语言存在。
Since the data itself - which seems to be json - contains double quotes, double quoted strings can't be used to wrap the data without escaping the double quotes within the data itself. 由于数据本身 - 似乎是json - 包含双引号,因此双引号字符串不能用于包装数据而不转义数据本身中的双引号。 Meaning it would need to look like this:
意思是它需要看起来像这样:
"{\n\"some.*.something\": \"myvalue\"\n}"
Basically single quoted strings could be used to avoid escaping the "
. 基本上单引号字符串可用于避免逃避
"
。
'{\n"some.*.something": "myvalue"\n}'
But since the data contains the newline escape sequence \\n
and escape sequences won't get expanded in single quoted strings , the author of the example in the question used ANSI C strings $''
. 但由于数据包含换行符转义序列
\\n
并且转义序列不会在单引号字符串中扩展,因此问题中示例的作者使用ANSI C字符串$''
。
Using ANSI C strings they get both: They can avoid to escape the double quotes in the data and still have the newline escape sequences getting expanded. 使用ANSI C字符串可以获得两者:它们可以避免转义数据中的双引号,并且仍然可以扩展换行符转义序列。
After the shell has expanded it, for curl the data looks like this: shell扩展后,对于curl,数据如下所示:
{
"some.*.something": "myvalue"
}
Further read: https://www.gnu.org/software/bash/manual/html_node/Quoting.html 进一步阅读: https : //www.gnu.org/software/bash/manual/html_node/Quoting.html
I still don't know what $'{}' mean. 我还是不知道$'{}'是什么意思。 However, I did get
myvalue
to be parameterized. 但是,我确实将
myvalue
设置为参数化。
"{\"some.*.something\":\"${myValueParamerterized}\"}"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.