Shell脚本——数组

时间:2020-05-04 15:17:49   收藏:0   阅读:50

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
评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!