Shell Script error: & quot; [: unaryoperatorexpected & quot; solve shell Script error: & quot; [: unaryoperatorexpected & quot; 2009-08-1118:00 when the matching string is equal, I used a statement like this: if [$ STATUS & quo
Shell Script error: "[: =: unary operator expected" solve shell Script error: "[: =: unary operator expected" when the matching string is equal, I used a statement like this: if [$ STATUS = "OK"]; then echo "OK" fi encountered the [:=: unary operator expected error during runtime, I can't find the cause. I tried to delete the spaces on both sides of the equal sign and the spaces in the brackets. finally, baidu found the cause. If [[$ STATUS = "OK"]; then echo "OK" fi, the cause is that if the STATUS value of the variable is null, then it becomes [= "OK"]. obviously [and "OK" are not equal and the [symbol is missing, so this error is reported. Of course, there are not always errors. if the variable STATUS value is not empty, the program will be normal, so such errors are hidden. You can also avoid this error using the following method: if ["$ STATUS" x = "OK" x]; then echo "OK" fi, of course, x can also be other characters. By the way, there are no double quotation marks in shell that are consistent in many cases.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service