【发布时间】:2014-09-25 23:31:53
【问题描述】:
我有一个长字符串,其中包含单引号 (')。我需要将此发送到 mysql,因此我尝试在 INSERT 语句期间将变量中的“'”替换为“\'”。
例子:
"This is the first single quote ', and this is the second '"
应该变成
"This is the first single quote \', and this is the second \'"
我见过几个使用脚本替换和 sed 的示例,但无法弄清楚这一点。 感谢任何帮助。
谢谢
【问题讨论】:
-
你看到this的回答了吗?你能适应吗?
-
很遗憾没有,因为我需要用两个字符(反斜杠和单引号)替换一个字符(单引号)
-
我认为这样的想法一定是解决方案
bar=${foo//\'/\\\\'}