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