Arrays: You use an index to store multiple data as a collection.
Normal array: The index of an array can only use integers
Associative arrays: Array indexes can use integers and strings (associative arrays are supported for versions above bash4.0)
Arrays are often used in interactions with loops or other judgments to make a higher sense.
Definition of an ordinary array
Array1= (a AB 3a)
The index of the array from 0 to the starting index
echo ${array1[0]} output: A
echo ${array1[2]} output: 12
Arrays can also be defined as
arry[0]= "Test0"
arry[1]= "Test1"
arry[2]= "Test2"
Print the values in the array at once
echo ${arry[*]} or echo ${arry[@]}
Output: Test0 test1 test2
Print all indexes of an array
Echo ${!arry[*]}
Output: 0 1 2
Print the total number of array values
echo ${#arry [*]}
Output: 3
Associative array definitions
First, declare that this array3 is an associative array
Declare-a arr
Associative array Assignment
index = value
Arr= ([App]=a [n-11]=b [110]=c]
can also
Array3[aa]=var1
Array3[a10]=var2
Print the values in the array at once
Echo ${array3[*]}
Print all indexes of an array
Echo ${!array3[*]}
This article is from the "Tiandaochouqin" blog, make sure to keep this source http://xiang99.blog.51cto.com/3583449/1413762