Chinaunix首页 | 论坛 | 博客
  • 博客访问: 537288
  • 博文数量: 65
  • 博客积分: 1158
  • 博客等级: 少尉
  • 技术积分: 1261
  • 用 户 组: 普通用户
  • 注册时间: 2012-07-18 22:07
文章分类

全部博文(65)

文章存档

2016年(1)

2014年(2)

2013年(9)

2012年(53)

分类: LINUX

2012-10-30 21:03:48

1.${test:-newvalue}
${test:-newvalue}主要就是测试test这个变量是不是已经定义了,如果已经定义了,那么还是打印这个定义了的值;但是如果没有的话,那么将打印这个newvalue的值,但是不会将这个值赋值给test变量。

例子:
[root@redhat ~]# test="blue"
[root@redhat ~]# echo "the sky is ${test:-grey} today";
the sky is blue today
[root@redhat ~]# unset test
[root@redhat ~]# echo "the sky is ${test:-grey} today";
the sky is grey today


[root@redhat ~]# unset test
[root@redhat ~]# echo "the sky is ${test:-grey} today";
the sky is grey today
[root@redhat ~]# echo ${test}   #这里是没有设置test变量的

2.${test:=newvalue}
下面来看看${test:=newvalue}
[root@redhat ~]# echo "the sky is ${test:=grey} today";
the sky is grey today
[root@redhat ~]# echo ${test}
grey              
#很显然的,${test:=newvalue}不光会在没有设置test变量的时候打印出newvalue的值,而且还会将newvalue的值赋值给test变量。
阅读(1183) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~