声明数组

declare -a  students  #声明普通数组
declare -A hotels #声明关联数组,使用关联数组必须声明

数组赋值

#1
students=(zhangsan lisi wangmazi xiaoming)
#2
students[0]='zhangsan'
students[1]='lisi'
students[2]='wangmazi'
students[3]='xiaoming'
#关联数组
declare -A zhangsan #先声明
zhangsan[bidthdday]='2021.02.20'
zhangsan[name]='zhangsan'
zhangsan[age]='20'
zhangsan[job]='it'

数组的使用

#显示所有数组
echo ${students[*]}
echo ${students[@]}
#显示数组的长度
echo ${#students[*]}
echo ${#students[@]}
#数组切片
echo ${students[*]:2:1} #跳过2个元素取一个 wangmazi
#删除数组
unset