${parameter:-word} #
ex1:
foo=
echo ${foo:-“hahaha”}
echo foo
输出的结果是 hahaha 空
ex2:
foo=“tengwang”
echo ${foo:-“hahaha”}
echo $foo
输出的结果是 tengwang tengwang
${parameter:=word} #
ex1:
foo=
echo ${foo:=hahaha}
echo $foo
输出的结果是 hahaha hahaha
ex2:
foo=“tengwang”
echo ${foo:=hahaha}
echo $foo
输出的结果是tengwang tengwang
${parameter:?word} #
ex1:
foo=
echo ${foo:?输入的变量为空,退出}
echo $foo
输出的结果是 -bash: foo: foo为空退出 空
ex2:
foo=“tengwang”
echo ${foo:?输入的变量为空,退出}
echo $foo
输出的结果是 tengwang tengwang
${parameter:+word} #
ex1:
foo=
echo ${foo:+hahaha}
echo $foo
输出的结果是 空 空
ex2:
foo=“tengwang”
echo ${foo:+hahaha}
echo $foo
输出的结果是 hahaha tengwang