How to escape single quotes within single quoted strings

前端 未结 23 2733
说谎
说谎 2020-11-21 06:20

Let\'s say, you have a Bash alias like:

alias rxvt=\'urxvt\'

which works fine.

However:



        
23条回答
  •  南旧
    南旧 (楼主)
    2020-11-21 06:37

    Simple example of escaping quotes in shell:

    $ echo 'abc'\''abc'
    abc'abc
    $ echo "abc"\""abc"
    abc"abc
    

    It's done by finishing already opened one ('), placing escaped one (\'), then opening another one ('). This syntax works for all commands. It's very similar approach to the 1st answer.

提交回复
热议问题