本文介绍了在双引号中传递命令行参数以卷曲的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的脚本使用了命令行参数,它需要将此参数传递给curl命令,并用双引号引起来。这是到目前为止我尝试过的简化版本:

My script is taking the command line argument and it needs to pass this to curl command in double quotes. This is the simplified version of what I tried so far:

json=$1;
echo $json;

curl -X POST -d'{ asin:\ $ json\, template: bolt, version: 1d}'-H内容类型:application / json http:// someURL

但是它不起作用。请帮助

But its not working. Please help

推荐答案

$-单引号字符串中的$变量不会扩展。 -d 参数需要用双引号引起来,或者至少 $ json 部分需要:

$-variables in single quoted strings don't get expanded. The -d argument needs be in double quotes, or at least the $json part needs to be:

curl -X POST -d '{"asin":"'"$json"'", "template":"bolt","version":"1d"}' -H "Content-Type: application/json" http://someURL

'-终止单引号字符串,然后跟随 $ json ,然后开始'

'-terminates the single-quoted string, then "$json" follows, and then ' starts an adjacent single quoted string.

$ json 变量不应扩展为包含未转义双精度字符的字符串引号或生成的json将被破坏。

The "$json" variable shouldn't expand to a string containing unescaped double quotes or the resulting json will be broken.

这篇关于在双引号中传递命令行参数以卷曲的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 18:05