Array of shell scripts

Definition:
A collection of various data types in sequence, called an array. He also has his own "array name", "array value", and "array index".
Basic operation example:
array=(1 2 3) The name of the array is array, which can be changed at will, separated by spaces, and the subscript starts from 0.
Get the length of the array: echo ${#array[*]} or echo ${#array[@]}
How to get: echo ${array[1]} = 2; echo ${array[]} = 1 2 3

Adding an array: directly use array[3]=4.
Delete array: use unset array[3]=4

Sometimes array=(...) is used. If there are many parentheses, we cannot write them one by one. At this time, commands are used instead.
Such as: array=($(ls)), this is equivalent to putting the result of the current directory ls into the array.

Guess you like

Origin blog.51cto.com/15013163/2576413