シェルスクリプトの配列を定義する方法のメモです。
方法その1
1行で羅列する方法です。値自体に空白がある場合はダブルクオーテーションで囲みます。
components=(abc def "gh i")
方法その2
複数行にまたがってもよいです。
components=(
abc
def
"gh i"
)
方法その3
インデックスを指定して要素を代入する方法です。
components[0]=abc
components[1]=def
components[2]="gh i"
方法その4
要素を1つずつ追加していく方法です。
components=()
components+=(abc)
components+=(def)
components+=("gh i")
出力例
for c in "${components[@]}"; do
echo $c
done
# 出力
# abc
# def
# gh i