linux中判断变量是否为空 -z选项

 

1、

root@DESKTOP-1N42TVH:/home/test# echo $a

root@DESKTOP-1N42TVH:/home/test# [ -z $a ] && echo "null" || echo "no null"    ## -z判断变量是否为空,空返回TRUE,非空返回FALSE
null
root@DESKTOP-1N42TVH:/home/test# a=100
root@DESKTOP-1N42TVH:/home/test# echo $a
100
root@DESKTOP-1N42TVH:/home/test# [ -z $a ] && echo "null" || echo "no null"    ## 非空返回FALSE
no null

 

posted @ 2022-04-30 22:30  小鲨鱼2018  阅读(611)  评论(0编辑  收藏  举报