0
#!/bin/bash
ARG_ARRAY=(num1 num2 num3 num4 num5 num6 num7 num8 num9 num10)
dir=$(find . -type f)
i=0
for f in ${dir[@]};do
printf "$((++i)) $f "
done
printf "\nPlease select the files:\n"
echo "Using the numbers like: 1 2 4 5 "
read ${ARG_ARRAY[@]}
echo $num1
echo $num2
echo $num3
echo $num4
echo $num5
echo $num6
echo $num7
echo $num8
echo $num9
echo $num10
for f in ${ARG_ARRAY[@]}
do
var=$f
echo ${$var}
done
上記のコードはすべてのファイルを表示する予定です。 usrがそれらを選択させてから、ユーザーが選択したファイル名を出力します。しかし、私は、これはシェルの複数の選択リストが失敗する
for f in ${ARG_ARRAY[@]}
do
var=$f
echo ${$var}
done
./test.sh: line 30: num1: command not found
./test.sh: line 30: num2: command not found
./test.sh: line 30: num3: command not found
./test.sh: line 30: num4: command not found
./test.sh: line 30: num5: command not found
./test.sh: line 30: num6: command not found
./test.sh: line 30: num7: command not found
./test.sh: line 30: num8: command not found
./test.sh: line 30: num9: command not found
./test.sh: line 30: num10: command not found
のエラーを取得しながら、このシーケンスが正常に
echo $num1
echo $num2
echo $num3
echo $num4
echo $num5
echo $num6
echo $num7
echo $num8
echo $num9
echo $num10
を印刷できます誰がこの問題を解決するために私を助けることができますか?なぜ2番目の方法が失敗するのですか?