Shell – Escaping Quotes in zsh Alias

aliasquotingshellzsh

Following on from this question about stripping newlines out of text, I want to turn this into a zsh alias as follows:

alias striplines=' awk " /^$/ {print \"\n\"; } /./ {printf( \" %s \",$0);}"'

I've tried escaping the quotes inside the awk script, but I'm getting this error:

awk: (FILENAME=bspsrobustness FNR=1) fatal: division by zero attempted

(The file is called bspsrobustness)

Is there a way to do what I want? I suppose I could turn this into an awk script rather than a zsh alias, is that my best option?

Best Answer

You could use a zsh function instead of an alias. No quoting hoops to jump through.

striplines() {
    awk '... awk body "with quotes" ...' "$@"
}
Related Question