Here is the code that I tried
#!/bin/bash
echo "Enter the size of array: "
read s
echo "Enter the elements of array: "
for (( i=0; $i<$s; i++ ))
do
read a[$i]
done
j=`expr $s - 1`
for (( i=0; $i<$j; i++ ))
do
temp = ${a[$i]}
a[$i] = ${a[$j]}
a[$j] = $temp
j = `expr $j - 1`
done
echo "The reverse array is"
for (( i=0; $i<$s; i++ ))
do
echo ${a[$i]}
done
And I'm getting the following errors
/home/2.sh: line 12: temp: command not found
/home/2.sh: line 13: a[0]: command not found
/home/2.sh: line 14: a[2]: command not found
/home/2.sh: line 15: j: command not found
/home/2.sh: line 12: temp: command not found
/home/2.sh: line 13: a[1]: command not found
/home/2.sh: line 14: a[2]: command not found
/home/2.sh: line 15: j: command not found
I was trying to swap the first element with the last element and so on, but the error says temp command not found. What am I doing wrong here?