变量转换为整数 [英] Converting variable to integer

查看:110
本文介绍了变量转换为整数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如下所示会显示一个警告,如果页面时间超过6秒加载的shellscript里。
问题是,在 myduration 变量不是整数。如何转换成整型?

  myduration = $(卷曲http://192.168.50.1/mantisbt/view.php?id=1 -w%{} TIME_TOTAL)GT;的/ dev / null的; [[$ myduration -gt 1]&放大器;&安培;回声`日期+'%Y%M%D%H%M%S'`花了超过6秒加载页面http://192.168.50.1/mantisbt/view.php?id=1>&GT ; /home/shantanu/speed_report.txt


解决方案

假设$ myduration是一个十进制或整数

  $ myduration = 6.5
$ myduration = $(printf上到%.0f$ myduration)
$回声$ myduration
6

The shellscript shown below will show a warning if the page takes more than 6 seconds to load. The problem is that the myduration variable is not an integer. How do I convert it to integer?

myduration=$(curl http://192.168.50.1/mantisbt/view.php?id=1 -w %{time_total}) > /dev/null ; [[ $myduration -gt 1 ]] && echo "`date +'%y%m%d%H%M%S'` took more than 6 seconds to load the page http://192.168.50.1/mantisbt/view.php?id=1 " >> /home/shantanu/speed_report.txt

解决方案

Assuming $myduration is a decimal or integer

$ myduration=6.5
$ myduration=$( printf "%.0f" $myduration )
$ echo $myduration
6

这篇关于变量转换为整数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆