${var:-DEFAULT}和${var=DEFAULT}的区别:
${var:-DEFAULT} If var not set or is empty, evaluate expression as $DEFAULT
${var=DEFAULT} If var not set, evaluate expression as $DEFAULT
如下例子,var先被赋值为空,然后用“=”赋值不会影响var的值,但用":-"操作符时可以改变var的值:
-----------------------------------------------------------------------
administrator@ubuntu:~/文档$ var=
administrator@ubuntu:~/文档$ echo ${var=z}
administrator@ubuntu:~/文档$ echo ${var:-z}
z
------------------------------------------------------------------------
还有一个例子就时对positional parameters的赋值,如对$1进行赋值就不能使用“=”,因为“=”只能用于一般的变量,也就是变量名以字母或下划线开头的变量,而":-"可以用来指定参数默认值:
administrator@ubuntu:~/文档$ echo ${1=xz}
bash: $1: cannot assign in this way
administrator@ubuntu:~/文档$ echo ${1:-xz}
xz
转自:http://blog.csdn.net/feixingfei/article/details/7079916