Bash
在bash中將3個單獨的數組組合成一個多維數組
是否可以在 bash 腳本中創建多維數組?
這些是我的 3 個數組:
arrayCITY=( NewYork LasVegas Detroit ) arraySTREET=( RoadStreet TreeStreet HighStreet ) arrayNUMBER=( 20 455 300 )
現在我想將這 3 個數組放在一個數組中——這可能嗎?然後我想在 txt 文件中顯示它們。現在我這樣做:
for ((i=0; i<${#arrayCITY[*]}; i++));do echo "${arrayCITY[i]} ${arraySTREET[i]} ${arrayNUMBER[i]}" >> TEXT.txt done
來自
man 1 bash
:Arrays Bash provides one-dimensional indexed and associative array variables. Any variable may be used as an indexed array; the declare builtin will explicitly declare an array. There is no maximum limit on the size of an array, nor any requirement that members be indexed or assigned contiguously. Indexed arrays are referenced using integers (including arithmetic expressions) and are zero-based; associative arrays are referenced using arbitrary strings. Unless otherwise noted, indexed array indices must be non-negative integers.
關鍵詞:
Bash 提供一維索引和關聯數組變數。
所以,不,bash 不支持多維數組。