if [str1 = str2] When two strings have the same content, the length is true
if [str1! = str2] When string str1 and str2 are not equal
If [-N str1] is true when the length of the string is greater than 0 (string non-null)
If [-Z str1] is true when the length of the string is 0 (empty string)
If [str1] is true when string str1 is non-empty
The shell uses-N to determine that the string is non-empty.
Error usage:
args=$*
If [-N $ARGS]
Then
Print "with argument"
Fi
print "Without argument"
Regardless of the pass-through parameters, will always enter if inside.
Reason: Because the IF statement is equivalent to if [-N],shell will treat it as if [str1], the-n nature is not empty, so it is positive.
Correct usage: You need to add double quotes on the $args, which is "$ARGS".
args=$*
If [-N "$ARGS"]
Then
Print "with argument"
Fi
print "Without argument"
Linux Shell if [-n] Correct use method