How to escape single quotes within single quoted strings

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

    If you have GNU Parallel installed you can use its internal quoting:

    $ parallel --shellquote
    L's 12" record
    
    'L'"'"'s 12" record'
    $ echo 'L'"'"'s 12" record'
    L's 12" record
    

    From version 20190222 you can even --shellquote multiple times:

    $ parallel --shellquote --shellquote --shellquote
    L's 12" record
    
    '"'"'"'"'"'"'L'"'"'"'"'"'"'"'"'"'"'"'"'"'"'"'"'"'"'"'"'"'"'"'"'"'"'s 12" record'"'"'"'"'"'"'
    $ eval eval echo '"'"'"'"'"'"'L'"'"'"'"'"'"'"'"'"'"'"'"'"'"'"'"'"'"'"'"'"'"'"'"'"'"'s 12" record'"'"'"'"'"'"'
    L's 12" record
    

    It will quote the string in all supported shells (not only bash).

提交回复
热议问题