0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

シェルスクリプトで配列同士を結合する

Posted at

なにこれ

  • 2つの配列を結合する方法を確認する

実行するコード

a=(1 2)
b=(3 4)
a+=(${b[@]})

for number in ${a[@]}
do
    echo $number
done

念のため解説

配列の作成

  • 変数への代入の際は、イコールの前後にスペースを入れない
  • 配列はカッコで囲う
  • 要素はスペースで区切る
a=(1 2)

配列の結合

  • 結合は+=で行う
  • 配列の要素を展開するには[@]をつける
  • すべての要素を再度配列にするためにカッコで囲う
a+=(${b[@]})
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?