When executing the shell script, the if judgment statement reports an error
#!/bin/bash if [ 0 == $testNum ] then echo "Check Result:0" fi
Testnum is not defined when it is used, and no assignment is empty (it was originally defined, but it is written incorrectly, similar to tsetnum). After the conversion, it is actually
if [ 0 == ]
Unequal and less [sign errors; Avoid the following
#!/bin/bash if [[ 0 == $testNum ]] then echo "Check Result:0" fi
Use “[[]]” to judge; Or add a character
#!/bin/bash if [ "0"x == "$testNumx"x ] then echo "Check Result:0" fi
In fact, for my mistakes, of course, it’s better to use “[]” ordinary judgment, and you can check the mistakes; However, this implementation is mostly used to judge whether the query value or the value given by other conditions meet the conditions. It is a normal scenario if it is empty, so you should improve your code
Detailed meaning to be added
Similar Posts:
- String null space error: binary operator expected
- Python: `if not x:` VS `if x is not None:` VS `if not x is None:`
- The shell script reported an error: not sure operator expected
- Shell script error: ‘[: =: unary operator expected’
- Solutions to the problem of too many arguments in Linux Bash
- If conditional statement in Bash reports an error [: missing `] ‘
- Several cases of error reporting in java.lang.nullpointerexception
- Linux Programmer Error: /bin/bash: No such file or directory [How to Solve]
- How to Solve Console error: index: 0, size: 0
- Concurrent notes (4): Notes on the use of wait / notify / notifyAll method