1. 程式人生 > >shell變量常用方法

shell變量常用方法

取數 數組長度 one shel 小括號 pos yum cnblogs art

變量之數組操作:

參考網址: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

shell變量常用方法