2016-06-07 99 views
1

我需要在字符串中使用在Bash中创建字符串。如何在bash中为字符串添加反斜杠和双引号

具体来说,我需要建立一个像这样的字符串:

string="{\"Name\":\"execute_recipes\", \"Args\":{\"recipes\":[$LIST_OF_RECIPES]}}"

所以,当我做回声$字符串,我不得不接受:

{\"Name\":\"execute_recipes\", \"Args\":{\"recipes\":[$LIST_OF_RECIPES]}}

+1

请更新问题,包括终端到终端的上下文。您所要求的内容对于生成JSON没有用处或有帮助。您可以运行例如'curl -d“{\”Foo \“:\”bar \“}”......“并不意味着您应该尝试使用反斜杠生成数据,因为这不是引用的工作方式。 –

+3

这听起来有点像[XY问题](http://meta.stackexchange.com/questions/66377/what-is-the-xy-problem) – rrauenza

回答

1

使用单引号括起来应该做的伎俩。单引号不会插入特殊字符。

string='{\"Name\":\"execute_recipes\", \"Args\":{\"recipes\":[$LIST_OF_RECIPES]}}'

相关问题