Shell脚本——数组

Shell脚本——数组

普通数组

[root@wshile ~]# books=(linux shell awk openstack docker)
[root@wshile ~]# echo ${books[1]}
shell  
[root@wshile ~]# echo ${books[@]}  // 查看所有变量
linux shell awk openstack docker
[root@wshile ~]# echo ${#books[@]}  // 查看变量长度
5
[root@wshile ~]# echo ${!books[@]}  // 获得数组的所有索引
0 1 2 3 4

 多维数组

shell默认不支持多维,需要声明

declare -A 变量名

示例

[root@wshile ~]# declare -A info
[root@wshile ~]# info=([name]=wsl [sex]=n [age]=18)
[root@wshile ~]# echo ${info[name]}
wsl
posted @ 2020-05-04 14:44  Wshile  阅读(240)  评论(0编辑  收藏  举报