bash alias command with both single and double quotes

后端 未结 3 2000
庸人自扰
庸人自扰 2020-11-27 13:58

I have this command that does what I want but I can\'t get to alias it in my .bashrc (note that it uses both single and double quotes):

svn status | awk \'$1         


        
3条回答
  •  被撕碎了的回忆
    2020-11-27 14:53

    Since Bash 2.04 there is a third (easier) way beside using a function or escaping the way @ffledgling did: using string literal syntax (here is an excellent answer).

    So for example if you want to make an alias of this onliner it will end up being:

    alias snap-removedisabled=$'snap list --all | awk \'$5~"disabled"{print $1" --revision "$3}\' | xargs -rn3 snap remove'
    

    So you just have to add the $ in front of the string and escape the single quotes.

    This brings a shellcheck warning you could probably safely disable with # shellcheck disable=SC2139.

提交回复
热议问题