默认值表达式1

${a-defaultvalue}

a如果没有定义,则表达式返回默认值,否则返回a的值;

demo1

a=""

ret1=${a-"/usr/local"}
echo "ret1:" $ret1

output:

demo2

ret1=${a-"/usr/local"}
echo "ret1:" $ret1

output:

默认值表达式2

${a:-defaultvalue}

a没有定义或者为空字符串,则表达式返回默认值,否则返回a的值;

demo1

a=""

ret1=${a:-"/usr/local"}
echo "ret1:" $ret1

output:

demo2

ret1=${a:-"/usr/local"}
echo "ret1:" $ret1

output:

05-11 10:52