Несколько изменений в вашем скрипте приведут к
#!/bin/bash
declare -a numbers # once numbers everywhere numbers
# Thanks @cyrus for the comment above, well you need an indexed array,
# not an associative one.
for((i=0;i<5;i++))
do # do-done is the preferred syntax
randNum=${RANDOM} # %RANDOM% is Windows command line stuff
# alternatively you could use a range say ${RANDOM:0:2}
# for values between 10^0 and 10^2, and so
echo $randNum
numbers[i]=$randNum
echo ${numbers[i]}
done
echo "After loop"
echo ${numbers[0]} # Should work
Синтаксису {}
с for-loop
, прочитайте этот ответ.