本文介绍了在bash中有条件地浮动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在bash中,我需要比较两个浮点数,为此,我在脚本中定义了一个浮点数,而另一个则作为参数读取:
in bash I need to compare two float numbers, one which I define in the script and the other read as paramter, for that I do:
if [[ $aff -gt 0 ]] then a=b echo "xxx "$aff #echo $CX $CY $CZ $aff fi但是我得到了错误:
[[:: -309.585300:语法错误:无效的算术运算符(错误标记为".585300")
[[: -309.585300: syntax error: invalid arithmetic operator (error token is ".585300")
怎么了?
谢谢
推荐答案使用awk
#!/bin/bash num1=0.3 num2=0.2 if [ -n "$num1" -a -n "$num2" ];then result=$(awk -vn1="$num1" -vn2="$num2" 'BEGIN{print (n1>n2)?1:0 }') echo $result if [ "$result" -eq 1 ];then echo "$num1 greater than $num2" fi fi更多推荐
在bash中有条件地浮动
发布评论