我试图执行简单的math,检查如果一个variables是大于或等于“1.5”,但我得到[: 2.41: integer expression expected
码:
reSum=$(expr "scale=1;555/230" | bc) if [ $reSum -ge "1.5" ]; then ... fi
我怎样才能在shell脚本中进行浮点比较?
if echo 555 230 | awk '{exit $1/$2 >= 1.5 ? 0 : 1}' then # ... fi
编辑:
最适合我的解决方案:
reSum=$(expr "scale=1;555/230" | bc) if (( `echo $reSum'>='1.5 | bc` )); then # anything fi
正如shellter所指出的, [ $(expr "$reSum > 1.5" | bc) ]
实际上是一个词典对比。 所以,例如, expr "2.4 > 18 | bc" // =>0
。
然而, (( `echo $reSum'>='1.5 | bc` ))
会进行浮点比较而不是字符串。