码迷,mamicode.com
首页 > 系统相关 > 详细

shell 浮点数和整数比较大小

时间:2020-05-11 10:34:23      阅读:181      评论:0      收藏:0      [点我收藏+]

标签:type   命令   pre   The   absolute   for   ash   bash   else   

我们知道在shell里面用> 或者gt lt都只是可以比较整数

 

在shell里面可以用bc命令和 awk命令比较两个浮点数或者浮点数和整数

例如

#!/bin/bash

a=7.2
b=8

if [ `echo "$a < $b"|bc` -eq 1 ] ; then
echo  "$a < $b "
else
echo "$a > $b "
fi
bc
Copyright 1991-1994, 1997, 1998, 2000 Free Software Foundation, Inc.
This is free software with ABSOLUTELY NO WARRANTY.
For details type `warranty‘. 
7.2>8
0
7.2<8
1

 

shell 浮点数和整数比较大小

标签:type   命令   pre   The   absolute   for   ash   bash   else   

原文地址:https://www.cnblogs.com/faberbeta/p/12867412.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!