linux系统中如何判断变量是否为空变量


 

1、

[root@rhel7pc1 test]# ls
[root@rhel7pc1 test]# a=100           ## 生成测试变量
[root@rhel7pc1 test]# echo $a 
100
[root@rhel7pc1 test]# echo $SHELL     ## 系统环境变量 /bin/bash
[root@rhel7pc1 test]# echo $b         ## b为空变量

[root@rhel7pc1 test]# [ -z $a ] && echo "null" || echo "no null"   ## -z判断是否为空变量
no null
[root@rhel7pc1 test]# [ -z $SHELL ] && echo "null" || echo "no null"
no null
[root@rhel7pc1 test]# [ -z $b ] && echo "null" || echo "no null" 
null

命令解释: -z 判断变量是否为空,  &&前为TRUE则执行&&后面的程序,   ||前为FALSE 则执行 || 后面的程序。

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM