Shell Script : If a Variable Is Null Or Not

主要是用z"$a" == z來判斷是否為Null或是空值

bash-3.2# vi test.sh
#!/bin/bash
if [ z"$a" == z ]; then
echo "a is null"
fi


bash-3.2# ./test.sh
a is null


bash-3.2# vi test.sh
#!/bin/bash
a=""
if [ z"$a" == z ]; then
echo "a is null"

bash-3.2# ./test.sh
a is null
fi

~
"test.sh" 6 lines, 62 characters
bash-3.2# ./test.sh
a is null
bash-3.2#