Ordinary Array:
Assign1:arrayname= (value1 value2 ...)
Assign2:arrayname[index]=value
Length: ${#arrayName [*]} or ${#arrayName [@]}
Indexes: ${!arrayname[*]} or ${#arrayName [@]}
Example:
#!/bin/bashgroup1= (Rio Amos) Group2[0]=billgroup2[1]=frankgroup2[2]=bruceecho group1 has ${#group1 [*]} Person[s]echo They is ${group1[*]}echo group2 has ${#group2 [@]} Person[s]echo they is ${group2[@]}
Associative Array:
Define:declare-a Arrayname
Assign1:arrayname= ([index1]=value1 [index2]=value2 ...)
Assign2:arrayname[index]=value
Length: ${#arrayName [*]} or ${#arrayName [@]}
Indexes: ${!arrayname[*]} or ${#arrayName [@]}
Example:
#!/bin/bashdeclare-a team1declare-a team2team1= ([rio]=1981 [amos]=1990] team2[frank]=1983team2[bill]=1984team2[ Bruce]=1990echo team1 has ${#team1 [*]} Person[s]echo They is ${!team1[*]}echo team2 has ${#team2 [@]} Person[s]echo they a Re ${!team2[@]}
This article is from the "Frank" blog, so be sure to keep this source http://zengfanhong.blog.51cto.com/8894077/1569554
Linux Array & Associative array