hyperpolyglot.org のこのリファレンス シートによると、次の構文を使用して配列を設定できます。
i=(1 2 3)
しかし、Ubuntuのデフォルトであるダッシュでエラーが発生し、/bin/sh
POSIX に準拠する必要があります。
# Trying the syntax with dash in my terminal
> dash -i
$ i=(1 2 3)
dash: 1: Syntax error: "(" unexpected
$ exit
# Working fine with bash
> bash -i
$ i=(1 2 3)
$ echo ${i[@]}
1 2 3
$ exit
リファレンス シートは誤解を招くものですか、それとも誤りですか?
はいの場合、配列またはリストを定義してPOSIXに準拠する正しい方法は何ですか?