Shell script error: [: =: unary operator expected “2009-08-11 18:00
When the matching strings are equal, I use a statement like this: if [$status = = OK]; Then echo “OK” fi in the run-time [: =: 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 brackets do not work, finally Baidu found the reason. Change the statement so that there is no error: if [[$status = $OK]]; The reason is that if the value of the variable status is empty, it will become [= “OK”]. Obviously [it is not equal to “OK” and lacks [symbol], so this error is reported. Of course, errors are not always made. If the value of the variable status is not empty, the program will be normal, so such errors are very hidden. Or the following method can be used to avoid this error: if [“$status” x = = “OK” x]; Of course, X can also be other characters. By the way, whether there are double quotes in the shell is consistent in many cases
Similar Posts:
- The shell script reported an error: not sure operator expected
- [Solved] Shell Script [: -ge/-le/=/… : unary operator expected (standard_in) 1: syntax error
- Script error: unary operator expected [How to Solve]
- Solutions to the problem of too many arguments in Linux Bash
- Shell script execution error [: 0: unary operator expected
- [Solved] MySQL Import csv File[Error Code] 1290 – The MySQL server is running with the –secure-file-priv option
- XML parsing & special character error
- Perl : Quantifier follows nothing in regex; marked by
- Expected indentation of 8 spaces but found [How to Solve]
- The solution of typeerror: expected string or buffer