How to compare two decimal numbers in bash/awk?

前端 未结 7 2208
傲寒
傲寒 2020-12-08 15:09

I am trying to compare two decimal values but I am getting errors. I used

if [ \"$(echo $result1 \'>\' $result2 | bc -l)\" -eq 1 ];then

7条回答
  •  清歌不尽
    2020-12-08 15:38

    Why use bc ?

    for i in $(seq -3 0.5 4) ; do echo $i ; if [[ (( "$i" < 2 )) ]] ; then echo "... is < 2";fi; done
    

    The only problem : the comparison "<" doesn't work with negative numbers : they are taken as their absolute value.

提交回复
热议问题