echo "Enter N " # enter N for number of inputs for the loop
read N # reading the N
#using c-style loop
for((i=1;i<=N;i++))
do
read -a arr # arr is the name of the array
done
echo ${arr[*]} # 1
echo ${arr[@]} # 2
Tried all the ways to display all the elements of the array but not getting the desired output. It's displaying the last element of the array.
declare -p arrayandfor i in ${array[@]}; do echo $i; doneorfor ((i = 0; i < ${#array[@]}; i++)); do echo ${array[$i]}; done(you should quote the array if whitespace is included) However, you will only ever read the last element if you attempt to enter the values on separate lines with your loop.