定義數組
arr=(1 2 3 4 5)
訪問數組
# echo ${arr[0]}
1
打印數組中所有的值
# echo ${arr[*]}
1 2 3 4 5
打印數組長度
# echo ${#arr[*]}
5
以上定義的數組,索引只能為數字,下面將介紹關聯數組
關聯數組
首先需要用單獨的語句將變量聲明為關聯數組
# declare -A arr_array
# arr_array=([apple]='100' [orange]='200') //定義數組 索引為apple orange
# echo ${arr_array[apple]} //數組指定索引的數組的值
100
獲取數組的索引列表
# echo ${!arr_array[*]}
orange apple