How to escape single quotes within single quoted strings

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

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

alias rxvt=\'urxvt\'

which works fine.

However:



        
23条回答
  •  萌比男神i
    2020-11-21 06:58

    I'm not specifically addressing the quoting issue because, well, sometimes, it's just reasonable to consider an alternative approach.

    rxvt() { urxvt -fg "#${1:-000000}" -bg "#${2:-FFFFFF}"; }
    

    which you can then call as:

    rxvt 123456 654321
    

    the idea being that you can now alias this without concern for quotes:

    alias rxvt='rxvt 123456 654321'
    

    or, if you need to include the # in all calls for some reason:

    rxvt() { urxvt -fg "${1:-#000000}" -bg "${2:-#FFFFFF}"; }
    

    which you can then call as:

    rxvt '#123456' '#654321'
    

    then, of course, an alias is:

    alias rxvt="rxvt '#123456' '#654321'"
    

    (oops, i guess i kind of did address the quoting :)

提交回复
热议问题