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
If you're building a double-quoted string somewhere that isn't echo or printf, like the commit string OP asked about, you can embed $(echo -e "\041") in the string where the exclamation point should be.
The exclamation mark is part of history expansion in bash. To use it you need it enclosed in single quotes (eg: 'http://example.org/!132' ). You might try to directly escape it with a backslash ( \ ) before the character (eg: "http://example.org/\!132" ).
Exclamation mark is for "Not" (like in boolean), -d flag is for folder exists in bash.
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 ("\!"
-> !
).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With