以下if-then-else出了什么问题?我永远无法击中其他人.
if [ $result > $value ]; then echo HEALTH: OK. Result is $result Value is $value exit 0 else echo HEALTH: CRITICAL. Result is $result which is over $value exit 2 fi # ./check_cw_auto <AWS variables> 5.0 HEALTH: OK. Result is 275593.8 Value is 5.0 # ./check_cw_auto <AWS variables> 10000000.0 HEALTH: OK. Result is 275593.8 Value is 10000000.0
我正在尝试创建一个nagios bash脚本.我确实尝试过-gt而不是>,但这会产生错误.例:
./check_cw_auto <AWS variables> 5.0 ./check_cw_auto: line 30: [: 256497.2: integer expression expected HEALTH: CRITICAL. Result is 256497.2 which is over 5.0
在[]中,两个字符串比较
lexicographically,而不是数字.你想使用-gt或-lt.
原文链接:https://www.f2er.com/bash/385339.html编辑:响应您的更新,bash没有浮点逻辑.你需要使用整数.