[ ]
內的每個元件都需要有空白鍵來分隔,以下說明空白鍵使用『□』來表示:
[ "$HOME" == "dywang" ] [□"$HOME"□==□"dywang"□] ↑ ↑ ↑ ↑
[ -z "$name" ]
判斷變數 name 是否是空字串?
[dywang@dywmac zzz]$ [ -z "$name" ] && echo "No name" || echo "name=$name" No name [dywang@dywmac zzz]$ name=dywang; [ -z "$name" ] && echo "No name" || echo "name=$name" name=dywang
[dywang@dywmac zzz]$ name="De Yu"; [ $name == "De Yu" ] && echo "Y" || echo "N" bash: [: too many arguments N
[dywang@dywmac zzz]$ [ '$name' == "De Yu" ] && echo "Y" || echo "N" N
[dywang@dywmac zzz]$ [ "$name" == "De Yu" ] && echo "Y" || echo "N" Y