Specify an array for a character
How to display an array
A=1echo $a1
A= (1234) echo $a1
echo ${a[@]} 1 2 3 4
echo ${a[*]}1234
Specifies the number of digits in the display array
echo ${a[0]}1
echo ${a[2]}3
echo ${a[3]}4
Echo ${a[4]} spaces
Add array
a[4]=9echo ${a[4]}9
Echo ${a[*]}
1 2 3) 4 9
To change an element in an array
a[2]=7echo ${a[*]}12749
Get the number of elements in an array
echo ${#a [@]} 5
Sort the 10 arrays to a random 0-9 composition
for inch 0 9 Do ' s//\n/g ' |sort-n
1759
4489
6142
9428
11344
15643
21679
25832
28684
30867
Remove one of the random 10 numbers
for inch 0 9 do a[$i]= $RANDOM; Done; Echo ${a[@]}
21159 31025 9479 4700 29562 30523 31666 2424 15437 7014
unset a[4]
Echo ${a[@]}
21159 31025 9479 4700 30523 31666 2424 15437 7014
Select a few values by selecting the specified elements in order
for inch 0 9 do a[$i]= $RANDOM; Done; Echo ${a[@]}
22278 2889 9019 10031 9383 31004 21595 20556 13672 26323
Echo ${a[@]:0:4}
22278 2889 9019 10031
Echo ${a[@]:1:3}
2889 9019 10031
Echo ${a[@]:4:4}
9383 31004 21595 20556
Shell Programming advanced 2.2 Shell Array