5

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

davidl
  • 151
  • 10

1 Answers1

9

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

Kevin
  • 53,822
  • 15
  • 101
  • 132
  • Can you tell me what I am doing wrong? `ssh server "awk 'del=(a&&a--) {print; da="\!"a} $0~pattern{if (da) {print "--"; da=0} a=A; if (B) {for(i=NR; i>> --; <<< awk: The statement cannot be correctly parsed. The source line is 1. ` – cokedude Aug 05 '21 at 20:04