Using this if statment in bash
:
if [ "$TOTAL_LOAD" >= "2" ];then
RESULT=$STATE_WARNING
msg_text="The system load on $HOST is greater than 200% please investigate {$TOTAL_LOAD}"
fi
Getting the error:
line 28: [: 0: unary operator expected
Not seeing the error in my ways. Anyone able to help?
Bash uses different operators for string vs arithmetic comparison. You want -ge
instead of >=
:
if [ "$TOTAL_LOAD" -ge "2" ];then
If I run this by hand I see the error:
pokyo. if [ "0" >= "2" ]; then echo hi; fi
bash: [: 0: unary operator expected
The problem is that ">=" is not a valid operator for test
. Instead you must write -ge
:
pokyo. if [ "0" -ge "2" ]; then echo hi; fi
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.