'How to do float comparison in shell scripting? [duplicate]

#! /bin/sh

echo "Enter the first number: "
read a 

echo "Enter the second number: "
read b

if [ $a -eq $b ]
then 
echo "$a is larger Number"

else
echo "$b is larger Number"
fi


Solution 1:[1]

How about using the basic calculator command bc?

#! /bin/sh

echo "Enter the first number: "
read a
echo "Enter the second number: "
read b

if (( $(echo "$a > $b" |bc -l) )); then
echo "$a is larger Number"
else
echo "$b is larger Number"
fi

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1