I want to compare two float values in shell script,

i.e. a = 0.1
b = 0.4

if ( $a < $b )then
expression1..
expression2..
expression3..
fi

if ( $a > 0.0 ) then
expression4..
expression5..
fi
could you please suggest me how to implement in shell script ?

Fianly i got solution from google here is it.

#! /usr/bin/ksh


isfirstgreater(){
LHS=$1
RHS=$2

min=`(echo $LHS ; echo $RHS) | sort -n | head -1`
if [ "$min" = "$LHS" ]; then
return 1
else
return 0
fi
}

isfirstless(){
LHS=$1
RHS=$2

min=`(echo $LHS ; echo $RHS) | sort -n | head -1`
if [ "$min" = "$LHS" ]; then
return 0
else
return 1
fi
}
checkval(){
FUNC=$1
ARG1=$2
ARG2=$3

echo -n "$FUNC $ARG1 $ARG2 ... "
$FUNC $ARG1 $ARG2

if [ $? -eq 0 ]; then
echo TRUE
else
echo FALSE
fi
}

checkval isfirstgreater 0.1 0.2
checkval isfirstless 0.1 0.2
checkval isfirstgreater 0.9993 0.9996

I want to compare two float values in shell script,

i.e. a = 0.1
b = 0.4

if ( $a < $b )then
expression1..
expression2..
expression3..
fi

if ( $a > 0.0 ) then
expression4..
expression5..
fi
could you please suggest me how to implement in shell script ?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.