Long story short, is it possible to make bc evaluate the following expression?
echo "!(2.2 >= 0) && !(2.2 < 10)" | bc
bash: !: event not found
I know this works:
echo "(2.2 >= 0) && (2.2 < 10)" | bc
1
So what am I doing wrong? The bc man page said that it has support for !expr, but I cannot seem to invoke it. I know it’s possible to work around the issue by negating the comparison signs, but I’d like to know how should the !expr be invoked in this case.
Much appreciated.
There is a feature of
bash, called “history expansion” (seeman bash): it handles!specially, even within double quotes.Replacing double quotes with single quotes should help (history expansion doesn’t happen there).
Also, history expansion doesn’t happen in non-interactive shells (that is, your example will work as is in a script).