【发布时间】:2015-11-30 18:03:26
【问题描述】:
好的,这可能非常明显,但对于我的生活,我无法弄清楚。 我想从带有 -d 标签的脚本中调用 curl 命令来传递一些 JSON
#!/bin/bash
JSON_STR='{"Some":"JSON","Data":"Here"}'
curl -x PUT "http://localhost:port/api/url" -d $JSON_STR
现在如果我回显 curl 命令来检查它的样子
echo curl -x PUT "http://localhost:port/api/url" -d $JSON_STR
一切看起来都很好:
curl -x PUT "http://localhost:port/api/url" -d '{"Some":"JSON","Data":"Here"}'
但是 API 抱怨转义字符,它看到
'{\"Some\":\"JSON\",\"Data\":\"Here\"}'
现在我明白了它们为什么存在(转义字符),但是如何在脚本命令中摆脱它们呢? bash 中有原始字符串吗?
提前致谢
【问题讨论】:
-
curl的手册页对于-d选项说数据应该是"url-encoded"。你试过这样做吗?
标签: linux string bash scripting