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

Popular posts from this blog

java - Jasper subreport showing only one entry from the JSON data source when embedded in the Title band -

serialization - Convert Any type in scala to Array[Byte] and back -

SonarQube Plugin for Jenkins does not find SonarQube Scanner executable -