I\'m trying to store the files listing into an array and then loop through the array again.
Below is what I get when I run ls -ls
command from the console.
Try with:
#! /bin/bash
i=0
while read line
do
array[ $i ]="$line"
(( i++ ))
done < <(ls -ls)
echo ${array[1]}
In your version, the while
runs in a subshell, the environment variables you modify in the loop are not visible outside it.
(Do keep in mind that parsing the output of ls
is generally not a good idea at all.)