I try the code below to store the command output in an array but the array elements cannot be printed after the "while loop" I mean in the last line of my code is there any problem in my code?
#! /bin/bash
ls -a | while read line
do
array[$i]="$line "
echo ${array[ $i ]}
((i++))
done
echo ${array[@]} <------------