Escaping an exclamation mark in a ssh remote call to awk?

awk, ssh

Solution

Bash evaluates `!` history manipulation even in double quotes. And if you escape it within quotes you just get `\!` (seriously, wtf bash?). You have to end the double quotes, add either `'!'` or `\!`, and reopen the double quotes.

ssh server1 "df ... && "\!"/^[a-zA-Z]/...}}'"

For the record, zsh handles the backslash escape within double quotes properly (`"\!"` -> `!`).

Problem

I have this line: ``` ssh server1 "df -h | sed 's/%/ /g' | awk '{ if (\$5 > 90 && !/^[a-zA-Z]/) { var1=1 }} END { if (var1 == 1) { print 1 } else { print 0 }}'" ``` However, this produces the following error: ``` bash: !/^[a-zA-Z]/: event not found ``` Not quite sure how I should escape the exclamation mark. Any ideas? Regards, David

Original source