Definition: array= (1 2 3)
Echo ${array[0]}
Echo ${array[1]}
Echo ${array[2]}
echo ${array[*]} all elements
Echo ${array[@]} The length of the array
Array Assignment
Array= (1 2 3) There are 3 elements in this array
Array[3]=4 4 elements in this array
Delete
unset array[0] removed the No. 0 element
Intercept
Array= (1 2 3 4 5)
${array[@]:1:3} intercept number 1th to 3rd
Results 2 3 4
Echo ${array[@]:3:2}
Results 4 5
Array substitution
Echo ${ARRAY[@]/5/6} Replaces 5 in the array with 6, temporarily in effect, and the element family has not been modified
Results 1 2 3 4 6
Turn the result into an array
array= ($ (LS))
Print
All elements ${array[@]} or ${array[*]}
Array length ${#array [@]} or ${#array [*]}
Single element ${array[i]}
Using an example of an array,
gamelist=${pwd}/gamelist forPidinch`awk '{print $7}'$gamelist ' DoPingtai=`awk '/\<" "$pid" "\>/{print $4}'$gamelist ' Daqu=`awk '/\<" "$pid" "\>/{print $6}'$gamelist ' Destdir=${pingtai}cq_lycqly_s$daqu dbname=${pingtai}cq_s$daqu Dbip=`awk '/\<" "$pid" "\>/{print}'$gamelist ' array=($(awk '/\<" "$pid" "\>/{print}'$gamelist)) forIinch{0..2} DoLanip=`Echo${array[i]}|Cut-D:-F1 ' Port=`Echo${array[i]} |Cut-D:-F2 'Echo${array[*]}Echo---------------------------------------------------------------# array=($(Echo${array[@]:1})) Echo$lanipEcho--------------------------------------------------------------Echo$port Done Done
View Code
Use of shell arrays