I have to pipe integers comparisons (and more complex arithmetic and boolean operations) to bc, and I have to keep track of syntax errors when some data is missing.
It seems I found some inconsistent behaviour with bc.
Of course :
echo "1==7" | bc
gives boolean 0
echo "==7" | bc
gives (standard_in) 1: syntax error
But :
echo -e "==1\n==7" | bc
(standard_in) 1: syntax error`
7
instead of 7
, one would expect (standard_in) 2: syntax error
on the second line.
For the sake of these explanations, I simplified the input of bc
but I have to resolve this strange behaviour with much more complex arithmetic and boolean operations.
WORKAROUND As @KamilCok noticed below, a workaround consists in inserting newlines
echo -e "==1\n==7" | awk 'ORS="\n\n"' | bc