Bash Scripting -z (bash shell script "if [ -z" )
Bash Shell scripting -z
Following example explains the use of –z option in bash script with If statement. In the first statement the abc string is assigned the null value. Then if [ -z "$ abc " ] checks that $abc has anything or not as we assigned null. “abc is null” printed out.
abc='' # Zero-length ("null") string variable. if [ -z "$ abc " ] then echo "\$ abc is null." else echo "\$ abc is NOT null." fi # $ abc is null. |
0 comments: