davidl
davidl

Reputation: 161

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

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

Upvotes: 6

Views: 2120

Answers (1)

Kevin
Kevin

Reputation: 56129

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 ("\!" -> !).

Upvotes: 10

Related Questions