我正在通过curl从API和API获取json,
$ curl -H 'Accept: application/json' http://127.0.0.1:8000/snippets/2/
{"id":2,"title":"","code":"print \"hello, work\"\n","linenos":false,"language":"python","style":"friendly"}
…,一切都很好。但是我想将json输出格式化为可以用作POST请求的表单数据的字符串。因此,我在上面的curl命令中添加了| sed -e's/\"/\'/g'
,但是shell希望我提供另一个报价。看到...
$ curl -H 'Accept: application/json' http://127.0.0.1:8000/snippets/2/ | sed -e's/\"/\'/g'
>
>
>
> '
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0sed: -e expression #1, char 8: unterminated `s' command
100 107 100 107 0 0 13375 0 --:--:-- --:--:-- --:--:-- 13375
(23) Failed writing body
我希望将输出中的所有"
都转换为'
。
更新:感谢您指出答案How to escape single quotes within single quoted strings?,但我不认为将命令行更改为...
$ curl -H 'Accept: application/json' http://127.0.0.1:8000/snippets/2/ | sed -e's/'"'"'/"'"'"/g'
...将解决我的问题...我会尝试的。尝试过并得到相同的错误。