Bash:精华

# 声明索引数组(以从0开始的整数做索引的数组)。以下三种等效。
declare -a   array
declare  array=(this is numeric array )
array=(this is numeric array )

 声明数组

索引数组:索引为0 1 2 ...
declare -a   array
declare  array=(this is numeric array )
array=(this is numeric array )
关联数组:索引为key(字符串)
declare -A array
declare  array=([A]=this is numeric array )
# 声明map索引
declare -A   map
declare -A   map=(k1=3 k2=ss k3=3)

  

# 引用数组元素的值
实施
# 读取数组所有key。索引数组的key,就是0开始的下标;map数组key,就是key列表。
# 读取索引数组
[root@gm ~]# echo ${!name[@]}  # 或 ${!name[*]}
1 2 3

# 读取单个元素的key。
[root@gm ~]# echo ${!array[1]}
this
[root@gm ~]# echo ${!name[k1]}
3

  

1 # gdfgfgsag .
2 fadfgd 
3 sdf

  

本篇文章出自“国民时代”,转载请注明转载出处。
原文地址:https://www.cnblogs.com/ChinaGo/p/10622708.html