The difference between the Linux array base "${a[*]} and $ A"
In bash, there are two ways to assign an array variable:
(1) name = (value1 ... valuen) the subscript starts at 0
(2) Name[index] = value
The following is a simple script stating the following:
#!/bin/bash# defining an array a=(a b c D E F) #把数组按字符串显示输出Echo${a[@]} #数组的长度表示 ${#A [*]}len=${#A [*]}Echo${#A [*]} #屏幕显示:6#改变数组元素的值A [3]='Vivian'Echo${a[*]} #屏幕显示: a b C Vivian E F # Loop output array element i=0 while[$i-LT $len] DoEcho${a[$i]}let i++ Done#循环输出数组元素的另一种写法, note that in the condition, the reference variable must use double quotation marks, otherwise the error for((j=0; j<"$len"; j=j+1 )) DoEcho${a[$j]} Done#循环输出数组元素的另一种写法, attention, ${a[.*]} cannot be written as $ A, $A default is the first element, if a ="a b c ded", you can write $ A forValueinch${a[*]} DoEcho$value DoneB="a b c d E F" forValueinch$B Do Echo$value DoneArray=($B)EchoArray_length: ${#array [*]} #就相当于B=(1 2 3 4), don't believe you can try Echo ${array[@]}Echo${array[@]} #上面的例子还可以改写成以下内容: forValueinch${array[*]} DoEcho$value Done