異なる名前の 3 つの同様のファイルを異なる配列に読み込もうとしています。不要なコードを使用したくなかったので、配列名をパラメーターとして受け入れる関数を作成しようとしていますが、「コマンドが見つかりません」というエラーが発生しています。
hello.sh ファイル コード:
#!/bin/bash
declare -a row_1
declare -a row_2
declare -a row_3
load_array()
{
ROW="$2"
let i=0
while read line; do
for word in $line; do
$ROW[$i]=$word
((++i))
done
done < $1
}
load_array $1 row_1
load_array $2 row_2
load_array $3 row_3
端末からこのファイルを次のように呼び出します。sh hello.sh 1.txt 2.txt 3.txt
私が得ているエラーのリスト:
hello.sh: line 13: row_1[0]=9: command not found
hello.sh: line 13: row_1[1]=15: command not found
hello.sh: line 13: row_1[2]=13: command not found
hello.sh: line 13: row_2[0]=12: command not found
hello.sh: line 13: row_2[1]=67: command not found
hello.sh: line 13: row_2[2]=63: command not found
hello.sh: line 13: row_3[0]=75: command not found
hello.sh: line 13: row_3[1]=54: command not found
hello.sh: line 13: row_3[2]=23: command not found