How to escape single quotes within single quoted strings

前端 未结 23 2165
说谎
说谎 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:44

    I don't see the entry on his blog (link pls?) but according to the gnu reference manual:

    Enclosing characters in single quotes (‘'’) preserves the literal value of each character within the quotes. A single quote may not occur between single quotes, even when preceded by a backslash.

    so bash won't understand:

    alias x='y \'z '

    however, you can do this if you surround with double quotes:

    alias x="echo \'y "
    > x
    > 'y
    

提交回复
热议问题