A= (1 2 3 4 5) define an array
echo $a show only 1 and cannot display all elements of the entire array
echo ${a[@]} displays all elements of the entire array, and @ can also be written as *
echo ${a[0]} displays only the first element in the array, marking 0 If the print does not exist for tag 5, the display is empty.
A[5]=6 adds an element and tags to the array
a[2]=7 Modifying the element of marker 2 to 7
echo ${#a [@]} in the print array, a total of several elements
unset a[2] within the array, delete an element and tag
Application of the array: sort 10 random numbers.
#!/bin/bash
For i in ' seq 0 9 '
Do
a[$1]= $RANDOM Assigning a value to an array
Done
echo ${a[@]}|sed ' s//\ n/g ' |sort-n after array processing, sort print \ n is a line break
Where $random is a randomly generated 3-5-bit number,sort is sorted on multiple lines, so use sed to handle whitespace as a newline
Echo $[a[@]:0:4] : 0 indicates starting from the 0 tag: 4 means displaying 4 elements
2.2-shell Array