How to compare two floating point numbers in Bash?

前端 未结 17 2364
無奈伤痛
無奈伤痛 2020-11-22 02:17

I am trying hard to compare two floating point numbers within a bash script. I have to variables, e.g.

let num1=3.17648e-22
let num2=1.5

No

17条回答
  •  Happy的楠姐
    2020-11-22 02:45

    You can use awk combined with a bash if condition:

    if awk 'BEGIN {exit !('$d1' >= '$d2')}'; then
        echo "yes"
    else 
        echo "no"
    fi
    

提交回复
热议问题