TECHIES WORLD

For Techs.... Techniques.... Technologies....

Linux

How to compare floating point numbers in bash

By default its not possible to compare floating point numbers in bash.

But we can acheive the same using bc command

For example,

#echo "5.2 > 5.4" | bc
0

#echo "5.6 > 5.4" | bc
1

If the result is greater than zero, first number is greater than second number and otherwise second number is greater than first number.

Leave a Reply