如何在bash中的字符串中添加反斜杠和双引号 [英] How to add backslash and double quote to a string in bash
本文介绍了如何在bash中的字符串中添加反斜杠和双引号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要在Bash中使用字符串中的 \"
创建一个字符串.
I need to create a string in Bash with \"
in the string.
具体来说,我需要创建一个像这样的字符串:
Specifically, I need to create a string like this:
string ="{\"名称\:\" execute_recipes \,\" Args \:{\"食谱\:[$ LIST_OF_RECIPES]}}""
所以当我回显$ string时,我必须接收:
So when I do echo $string, I have to receive:
{\名称\":\"execute_recipes \",\"Args \":{\食谱\":[$ LIST_OF_RECIPES]}}
推荐答案
使用单引号可以解决问题.单引号不会插入特殊字符.
Using single quotes around should do the trick. Single quotes don't interpolate special characters.
string ='{\名称\":\"execute_recipes \",\"Args \":{\食谱\":[$ LIST_OF_RECIPES]}}''
这篇关于如何在bash中的字符串中添加反斜杠和双引号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文