There are two types of
data in the shell: one is a numeric type, the other is a string type , and although the shell itself is a weak type, it can be so distinguished.
If we need to store multiple values in a variable in the shell, we need a more convenient type array
Array in the shell is enclosed in parentheses each value is separated by a space to define an
array
A= (1 2 3 4 5)
A= ("A" "B" "C" "D" "E")
A= (1 "A" 2 "B")
It's all possible.
The use of arrays
Get the length of the array: ${#a [*]} or ${#a [@]}
Get all the values in the array: ${a[*]} or ${a[@]}
Get the specified value in the array: ${a[digit]} #digit表示数字下标, that is, the position of each element of the array is counted from 0
Gets the value of the contiguous position in the array: ${a[*]:0:3} Here is a method using a string intercept ${var: Start position: Length}
Modify the value of an array a[subscript]= value
Iterating through an array with a For loop
For i in ${a[@]}; Do
echo I
Done
Delete a value in an array
unset a[Subscript]
An array of special variable types in the shell