Write special character in bash string

This question already has an answer here:

  • How to escape single quotes within single quoted strings? 19 answers

  • 你可以使用外部的"代替:

    echo "truncate 'testTruncate' "|hbase shell 
    

    You can include a ' in a string that is quoted by ' as follows:

    echo 'O'''Brien'
    

    or

    echo 'O'"'"'Brien'
    

    In both case you will get O'Brien as output. Note that in both case, we there essetially 3 strings, one next to the other, eg 'O' , ' , 'Brien' .

    This looks ugly, but unfortunately backslash escapes are not supported in single quoted strings in bash.

    链接地址: http://www.djcxy.com/p/57132.html

    上一篇: 引用和转义ssh命令行

    下一篇: 在bash字符串中写入特殊字符