1. The most straightforward and straightforward judgment
Without those if statements, directly shorten the amount of code.
2. The variable is caused by "" quotation marks
As shown below:, you can get the result is NULL.
#!/bin/sh a= if [!-n "$a"]; then echo ' is null ' else echo ' NOT NULL '
3. Judging directly by variables
The results are as follows: Is NULL, the same as the first method, but the code is a little longer, it is recommended to use the second way of judging, simple and clear.
#!/bin/sh a= if [! $a]; then echo ' is null ' else echo ' NOT NULL '
4. Use test to determine
The results are: A is not set!
#!/bin/sh a= if test-z "$a" then echo "A was not set!" else echo "A is set!"
5. Use "" to determine
#!/bin/sh a= If ["$a" = ""]; Then echo "A was not set!" else echo "A is set!"
This situation is easy to make the foot of the newspaper wrong
Transferred from: http://luxiaok.blog.51cto.com/2177896/925548
If the shell determines that a variable is empty