When using - Z
or - N
to judge a variable empty, it should be noted that if you use the form of [- N ${Arg}]
directly, if there are spaces in ${Arg}
it will report an error
#!/bin/bash
ARG="sd dd"
if [ -n ${ARG} ]; then
echo 'ARG:' ${ARG}
else
echo 'ARG is empty.'
fi
Output:
line 27: [: sd: binary operator expected
ARG is empty.
Password> [- N ${Arg}] password> [- n “${Arg}]
Similar Posts:
- 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
- Shell script error: ‘[: =: unary operator expected’
- [Solved] Shell Script [: -ge/-le/=/… : unary operator expected (standard_in) 1: syntax error
- Invalid prop: type check failed for prop “value”. Expected String, Number, got Object found in
- If conditional statement in Bash reports an error [: missing `] ‘
- [Solved] Github Action Error: Error: Unable to process file command ‘env’ successfully.
- [Solved] Shell Error: syntax error: invalid arithmetic operator (error token is “
- Spring MVC upload file error string cannot be converted to multipartfile