在bash中有条件地浮动

编程入门 行业动态 更新时间:2024-10-24 08:23:13
本文介绍了在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中有条件地浮动

本文发布于:2023-10-24 08:45:25,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1523478.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:中有   条件   bash

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!