标签:
冒号:用来检验变量是否设置过,如果没有冒号,则认为设置过,不替换
$fruit=peach
$echo ${fruit:-plum}
peach
$fruit=
$echo ${fruit:-plum}
plum
$echo $fruit
$
$name=
$echo ${name:=Peter}
Peter
$echo $name
Peter
$foo=grapes
$echo ${foo:+pears}
pears
$echo $foo
grapes
$echo ${namex:?"namex is undefined"}
namex: namex is undefined
$echo name=${1:?"requires an argument"} //适用于脚本中检测位置参量
1: requires an argument
echo ${y?}
y: parameter null or not set //打印默认消息
$var=notebook
$echo ${var:0}
notebook
$echo ${var:0:4}
note
$echo ${var:4:4}
book
标签:
原文地址:http://www.cnblogs.com/pandachen/p/4591872.html