Shell脚本——数组

Posted Wshile

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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

以上是关于Shell脚本——数组的主要内容,如果未能解决你的问题,请参考以下文章

用于确保在任何给定时间仅运行一个 shell 脚本的 shell 片段 [重复]

常用python日期日志获取内容循环的代码片段

shell脚本引用expect

Shell脚本(函数,shell中的数组)

shell脚本中的函数,shell中的数组,shell项目-告警系统

shell中的函数数组告警系统脚本