变量替代
1.${变量名-新的变量值}
2.${变量名:-新的变量值}
${变量名-新的变量值}
1.变量没有被赋值的情况下
[root@xiudaochengxian test]# unset url
[root@xiudaochengxian test]# echo $url
[root@xiudaochengxian test]# url=www.xiuxian.com
[root@xiudaochengxian test]# echo $url
www.xiuxian.com
[root@xiudaochengxian test]# echo ${url-www.baidu.com}
www.xiuxian.com
[root@xiudaochengxian test]# unset url
[root@xiudaochengxian test]# echo ${url-www.baidu.com}
www.baidu.com
2.变量被赋值(包括空值)的情况下
[root@xiudaochengxian test]# url2=
[root@xiudaochengxian test]# echo ${url2-www.baidu.com}
.${变量名:-新的变量值}
1.变量没有被赋值(包括空值)的情况下
[root@xiudaochengxian test]# unset url
[root@xiudaochengxian test]# echo $url
[root@xiudaochengxian test]# url=www.xiuxian.com
[root@xiudaochengxian test]# echo $url
www.xiuxian.com
[root@xiudaochengxian test]# echo ${url:-www.baidu.com}
www.xiuxian.com
[root@xiudaochengxian test]# unset url
[root@xiudaochengxian test]# echo ${url:-www.baidu.com}
www.baidu.com
2.变量被赋值的情况下:不会被替代
[root@xiudaochengxian test]# url2=
[root@xiudaochengxian test]# echo $url2
[root@xiudaochengxian test]# echo ${url2:-www.baidu.com}
www.baidu.com