${变量-预设值} 变量不存在输出后面的预设值,变量存在输出本身的值
1: unset aa 2: r=${aa-"Naas"} 3: echo $r
result : Naas
1: aa=ose2 2: r=${aa-"Naas"} 3: echo $r
result : ose2
分辨不存在和空值的差异
1: unset var 2: r=${var-'unset'} && [ "$r" != 'unset' ] && r=empty 3: echo "var is $r"
result : var is unset
1: var= 2: r=${var-'unset'} && [ "$r" != 'unset' ] && r=empty 3: echo "var is $r"
result : var is empty