floating point variable in UNIX script

HI all,

Can someone help me how to use or assign a floating point value in a variable in a unix script. I dont know how to use it.

for example, I am to assign a variable VAR1 a value of 2.34 and evaluate if a certain vaue is greater or less than to it.

That is,

if var1 > 2.13 will do something...

Please help me. I would appreciate your help.

Thanks
Darry

#!/bin/ksh

a=1.72
b=1.71

if [ "$(echo "if (${a} > ${b}) 1" | bc)" -eq 1 ] ; then
   echo ">"
else
   echo "<"
fi;

=>var1=2.13
=>if [ $var1 \< 3 ]
> then
> echo hi
> else
> echo by
> fi

This works for me, the > and < are redirection operators, so just escape them by the \

Will only work with bash, though.

yeah it will work only in bash

use awk in that case

echo $var1|awk ' {if ($0 < 3 ) { print "hi" } else { print "by" } }'

Hi vgersh99,

Can you please tell me how to use the else clause in the if statement you have written. (i.e. "if (${a} > ${b}) 1" | bc)" )

so that i will have something like this
"if (${a} > ${b}) 1 else 0" | bc)"
But as it is this is not working in ksh.

could you elaborate on what you've tried and what exact is not working?

My requirement is if $a > $b then if have to execute a set of statements else another set of statements.
if [ `echo "if (${a} > ${b}) 1 else 0" | bc` -eq 1 ]
then
....
.....
else
.....
.....
fi