bashで3つの別々の配列を1つの多次元配列にマージする

bashで3つの別々の配列を1つの多次元配列にマージする

Bashスクリプトで多次元配列を作成できますか?

私の3つの配列は次のとおりです。

arrayCITY=( NewYork LasVegas Detroit )
arraySTREET=( RoadStreet TreeStreet HighStreet )
arrayNUMBER=( 20 455 300 )

さて、この3つの配列を1つの配列に入れたいと思います。これは可能ですか?その後、txtファイルとして表示したいと思います。今私はこれをします:

for ((i=0; i<${#arrayCITY[*]}; i++));do
  echo "${arrayCITY[i]} ${arraySTREET[i]} ${arrayNUMBER[i]}" >> TEXT.txt
done

ベストアンサー1

から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は1次元のインデックスと連想配列変数を提供します。

いいえ、bashは多次元配列をサポートしません。

おすすめ記事