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 则执行 || 后面的程序。