SHELL脚本编程-普通数组(列表)和关联数组(字典)
作者:尹正杰
版权声明:原创作品,谢绝转载!否则将追究法律责任。
一.数组相关概述
变量:
存储单个元素的内存空间 数组:
存储多个元素的连续的内存空间,相当于多个变量的集合 数组名和索引 索引:编号从0开始,属于数值索引 注意:索引可支持使用自定义的格式,而不仅是数值格式,即为关联索引,bash4.0版本之后开始支持(关联数据使用时必须提前声明类型)
bash的数组支持稀疏格式(索引不连续) 声明数组: declare -a ARRAY_NAME declare -A ARRAY_NAME: 关联数组 注意:普通数组不用事先声明就可以使用,但关联数组必须提前声明才能使用,且两者不可相互转换。
[root@node101.yinzhengjie.org.cn ~]# bash --version GNU bash, version 4.2.46(2)-release (x86_64-redhat-linux-gnu) Copyright (C) 2011 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html> This is free software; you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. [root@node101.yinzhengjie.org.cn ~]#