Expanding a bash array only gives the first element
Solution 1:
$files
expands to the first element of the array.
Try echo $files
, it will only print the first element of the array.
The for loop prints only one element for the same reason.
To expand to all elements of the array you need to write as ${files[@]}
.
The correct way to iterate over elements of a Bash array:
for file in "${files[@]}"