使用选项在shell脚本中打印单引号
这个问题在这里已经有了答案:
您不能在bash中嵌套单引号,因此该行被解释为
/bin/bash -l -c 'echo "'John'"'
                |......| ---------- single quoted
                       |....| ----- not quoted
                            |.| --- quoted
所以,正确地逃避单引号:
/bin/bash -c 'echo "'''John'''"'
或者,如果单引号中的字符串非常简单,
/bin/bash -c 'echo "''John''"'
尝试删除双引号并转义单引号:
/bin/bash -l -c "echo 'John'"
  一个常见的解决方法是使用printf因此您不需要在格式字符串中使用文字单引号。 
bash -l -c 'printf "x27Johnx27n"'
  (在这里使用bash -l可能是误导和不可移植的。) 
上一篇: Print single quotes in shell script using option
下一篇: Quotation marks cancelling out command in bash to pass to variable
