我需要准备包含要通过CURL发送的撇号的JSON。 JSON的示例:
{"myField":"Apos'test"}
我需要作为输出的JSON示例:
{"myField":"Apos'\''test"}
我尝试过的事情:
sed -e "s/'/'\\\''/g" <<< {"myField":"Apos'test"}
输出:
{myField:Apos'\''test}
我不明白为什么它会删除双引号。
P.S。不必使用sed,任何其他标准linux工具都可以使用。
答案 0 :(得分:0)
尝试一下:
#/bin/bash
replacement=$((cat << EOT
{"myField":"Apos'test"}
EOT
) | sed "s|'|'\\\''|")
echo $replacement
输出:
{"myField":"Apos'\''test"}
答案 1 :(得分:0)
It doesn't
If it was because you used <<< , here, of which "" pair was parsed, expanded and dropped by the shell you're in
$ cat d
{"myField":"Apos'test"}
$ sed -E "s/'/'\\\''/g" d
{"myField":"Apos'\''test"}