shell变量常用方法
变量之数组操作:
参考网址:http://www.jb51.net/article/55253.htm
#直接赋值 [root@local-yum yum.repos.d]# name[0]=chengd [root@local-yum yum.repos.d]# name[1]=xrd [root@local-yum yum.repos.d]# name[2]=cxx #小括号赋值 [root@local-yum yum.repos.d]# age=(20 19 18) #遍历数组变量 [root@local-yum yum.repos.d]# for i in ${name[@]};do echo $i ;done chengd xrd cxx [root@local-yum yum.repos.d]# for i in ${age[@]};do echo $i ;done 20 19 18 #获取数组长度 [root@local-yum yum.repos.d]# echo ${#name[@]} 3 [root@local-yum yum.repos.d]# echo ${#age[*]} 3 #删除数组元素 [root@local-yum yum.repos.d]# unset name[1] [root@local-yum yum.repos.d]# echo ${#name[@]} 2 [root@local-yum yum.repos.d]# for i in ${name[@]};do echo $i ;done chengd cxx #删除数组 [root@local-yum yum.repos.d]# unset name [root@local-yum yum.repos.d]# echo ${#name[@]} 0 [root@local-yum yum.repos.d]# for i in ${name[@]};do echo $i ;done