Sign up ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

We tested our script and it fails on negative floating points comparison in bash. What are we doing wrong ?

FLP=$(bc <<< "scale=5; ($F2 - $F1)/$F2 * 100")
if [ $FLP -eq "1" ]; then
    echo " greater"
    echo "smaller"

It keeps printing "greater" with -99.99900

Thanks all for help

share|improve this question

2 Answers 2


FLP=$(bc <<< "scale=5; (${F2} - ${F1})/${F2} * 100")

if (( $(echo "${FLP} 1" | awk '{print ($1 > $2)}') )); then
  echo "greater"
  echo "smaller"

Adopted from:

share|improve this answer

Bash help for -eq states that it compares INTEGER types. There is no floating point support in [.

What I'd recommend is that you're already using bc to do the calculation -- why don't you use bc also to do the comparison? As in, instead of if A < B, you could test for if B-A > 0, where the subtraction is done by bc, and the signal check be easily done in bash.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.