Reputation: 11
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?
Upvotes: 1
Views: 19493
Reputation: 22559
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
Upvotes: 1
Reputation: 53626
Bash uses different operators for string vs arithmetic comparison. You want -ge
instead of >=
:
if [ "$TOTAL_LOAD" -ge "2" ];then
Upvotes: 5