Array, and parameter transfer between function and array

Array

How to define an array

           (30 20 10 60 50 40)
对应的索引号   0  1  2  3  4  5

method one

Array name=(value0 value1 value 2 …)

Method Two

Array name=([0]=value [1]=value [2]=value...)

Method Three

List name = "value0 value1 value2..."
Array name = ($list name)

Method Four

Array name [0] = "value"
Array name [1] = "value"
Array name [2] = "value"

How to get the data list

echo ${
    
    arr_number[*]}
echo ${
    
    arr_number[@]}

Insert picture description here
Insert picture description here
Insert picture description here
Insert picture description here

Get an element with a fixed index

Insert picture description here

Get the length of the array

Insert picture description here

Data types included in the array

使用" "'  '定义

Numerical type

Insert picture description here

Character type

Insert picture description here

Array traversal-the different meanings of * and @

Insert picture description here

Array slice

Insert picture description here

Array replacement

Insert picture description here
Insert picture description here

Array delete

Insert picture description here
Insert picture description here

Array append element

method one

Insert picture description here

Method Two

Insert picture description here

Method Three

Insert picture description here

Method Four

Insert picture description here

Pass array parameters to the function

If you directly use the array as a function parameter, the
Insert picture description here
Insert picture description here
solution to the problem is to first decompose the value of the array variable into a single value, and then use it as a function parameter
Insert picture description here
Insert picture description here

Return an array from a function

Insert picture description here
Insert picture description here
Insert picture description here
Insert picture description here

Guess you like

Origin blog.csdn.net/Jun____________/article/details/114677105