击:整数EX pression预期 [英] Bash: Integer expression expected
本文介绍了击:整数EX pression预期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想进行简单的数学运算,检查一个变量是大于或等于1.5
但我发现 [:2.41:整数EX pression有望
code:
reSum = $(表达式的规模= 1;二百三十〇分之五百五十五| BC)如果[$ reSum -ge1.5];然后
...
科幻
我该怎么办浮点运算的shell脚本?
解决方案
如果有回声555 230 | AWK'{退出$ 1 / $ 2 - = 1.5? 0:1}
然后
#...
科幻
I'm trying to perform simple math, to check if a variable is greater or equal to "1.5"
but I'm getting [: 2.41: integer expression expected
Code:
reSum=$(expr "scale=1;555/230" | bc)
if [ $reSum -ge "1.5" ]; then
...
fi
How can I do floating-point comparisons in shell script?
解决方案
if echo 555 230 | awk '{exit $1/$2 >= 1.5 ? 0 : 1}'
then
# ...
fi
这篇关于击:整数EX pression预期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文