Floating point comparison in shell

前端 未结 7 1395
伪装坚强ぢ
伪装坚强ぢ 2020-11-27 17:38

Can you please suggest to me the syntax for doing floating point comparison in a Bash script? I would ideally like to use it as part of an if statement. Here is

7条回答
  •  遥遥无期
    2020-11-27 18:16

    yu can use this awk comparison inside a if clause, it will print 1 (true) if the condition is true else 0 (false), and those values will be interpreted as boolean vals by the if

    if (( $(awk 'BEGIN {print ("'$result'" <= "'$key1'")}') )); then
        echo "true"
    else
        echo "false"
    fi
    

提交回复
热议问题