I am trying to output the values of array element but I am getting weird output. Please have a look at it and help me solve it. Thank you.
n=2
declare -a myarray[$n]
myarray[0]=hey
myarray[1]=hello
myarray[2]=bye
for i in ${myarray[@]}
do
echo $i
done
Output:
robin@robin-VirtualBox:~/lx$ sh array.sh
array.sh: 2: array.sh: declare: not found
array.sh: 3: array.sh: myarray[0]=hey: not found
array.sh: 4: array.sh: myarray[1]=hello: not found
array.sh: 5: array.sh: myarray[2]=bye: not found
array.sh: 6: array.sh: Bad substitution