默认值表达式1
${a-defaultvalue}
a如果没有定义,则表达式返回默认值,否则返回a的值;
demo1
a=""
ret1=${a-"/usr/local"}
echo "ret1:" $ret1
output:
ret1:
demo2
ret1=${a-"/usr/local"}
echo "ret1:" $ret1
output:
ret1:/usr/local
默认值表达式2
${a:-defaultvalue}
a没有定义或者为空字符串,则表达式返回默认值,否则返回a的值;
demo1
a=""
ret1=${a:-"/usr/local"}
echo "ret1:" $ret1
output:
ret1:/usr/local
demo2
ret1=${a:-"/usr/local"}
echo "ret1:" $ret1
output:
ret1:/usr/local
原文地址:https://www.cnblogs.com/lanyangsh/p/10055900.html
时间: 2024-10-10 01:41:00