bash - Compare two alphanumeric variables mixed with special expression in shell script -
i want compare 2 alphanumeric strings , below bash expression think should job. i'm getting blank result. please advise.
:~$ echo $tempnow $threshold +60.0°c +80.0°c :~$ res=`echo "$tempnow $threshold" | awk '{ if($1 > $2) print "exceeds"; else echo "normal" }'` :~$ echo $res :~$
there no echo
in awk.
you can use:
echo '+90.0°c +80.0°c' | awk '{ print ($1+0 > $2+0 ? "exceeds" : "normal") }' exceeds echo '+60.0°c +80.0°c' | awk '{ print ($1+0 > $2+0 ? "exceeds" : "normal") }' normal
also note use of +0
convert fields numeric values.
Comments
Post a Comment