$filesexpands to the first element of the array. Try it echo $files, it will print only the first element of the array. The for loop prints only one item for the same reason.
To expand all elements of an array, you need to write how ${files[@]}.
The correct way to iterate over the elements of a Bash array:
for file in "${files[@]}"
janos source
share