I am trying to search files starting with the name properties.* inside a directory and assign to an array. When I try to print the array outside the loop, it shows empty. Inside the do loop, it prints fine. How will make this array global or take the values outside the loop. Please share your thoughts.
#!/bin/bash
NAMES=("")
x=0
find /opt/scripts/ -type f -name "properties.*" | while read FILES
do
x=$(( $x + 1 ))
NAMES[$x]=${FILES}
done
echo ${NAMES[@]}