Shell foot This report wrong: "[: =: unary operator expected"
When matching strings are equal, I use a statement like this:
if [$STATUS = = "OK"]; Then
echo "OK"
Fi
At run time appeared [: =: unary operator expected error, has been unable to find the reason, tried to delete the space on both sides of the equal sign and the space in parentheses did not work, finally Baidu a bit, to find the reason. Change the sentence so that it doesn't go wrong.
if [[$STATUS = "OK"]];
Then
echo "OK"
Fi
The reason is because if the variable status value is empty, then it becomes [= "OK"], obviously [and "OK" is not equal and missing the [symbol, so reported this error. Of course not always error, if the variable status value is not empty, the program is normal, so this error is still very covert.
Or you can avoid this error by using the following method: if ["$STATUS" x = = "OK" x]; Then Echo
"OK" fi. Of course, X can also be other characters. Incidentally, there are no double quotes in the shell that are consistent in many cases.
Transferred from: http://hi.baidu.com/vishare/blog/item/bd8ab9ee289753252cf53417.html
Shell foot This report wrong: "[: =: unary operator expected"