如何比较在bash / awk的两位十进制数? [英] How to compare two decimal numbers in bash/awk?
本文介绍了如何比较在bash / awk的两位十进制数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想比较两个十进制数,但我得到的错误。
我用
I am trying to compare two decimal values but I am getting errors. I used
if [ "$(echo $result1 '>' $result2 | bc -l)" -eq 1 ];then
由其他堆栈溢出线程建议。
as suggested by the other Stack Overflow thread.
我收到错误。
什么是去对此正确的方法是什么?
What is the correct way to go about this?
推荐答案
您可以使用bash的数字语境做到这一点:
You can do it using Bash's numeric context:
if (( $(echo "$result1 > $result2" | bc -l) )); then
BC
将输出0或1,(())
将间preT他们为假或分别实现。
bc
will output 0 or 1 and the (( ))
will interpret them as false or true respectively.
使用AWK同样的事情:
The same thing using AWK:
if (( $(echo "$result1 $result2" | awk '{print ($1 > $2)}') )); then
这篇关于如何比较在bash / awk的两位十进制数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文