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 則執行 || 后面的程序。