最近在使用 curl 发送post请求的时候,需要带上自定义的变量,示例如下:
name="Tom"
age=18
msg="my name is ${name}, age is ${age}"
echo ${msg}
curl -X POST "http://xxx.com" -H "Content-Type:application/json" -d "{\"message\":{\"header\":{\"body\":[{\"type\":\"TEXT\",\"content\":\"${msg}\"}]}}"
有几点需要注意:
- json的key必须是双引号
"content",所以使用\进行转义 - 如果
-d后面的使用单引号'{"message": ...}',那么必须是"'${msg}'"进行转义,但是msg里不能有空格等特殊字符,所以建议采用第一点
4419

被折叠的 条评论
为什么被折叠?



