6
1

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 1 year has passed since last update.

シェルスクリプトの配列を定義するには

Posted at

シェルスクリプトの配列を定義する方法のメモです。

方法その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
6
1
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
6
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?