Sorting with **gawk** expression (supported by **bash**'s `readarray`):
Sample array of filenames containing **whitespaces**:
filearray=("dir1/name 0010.pdf" "dir2/name 0003.pdf" "dir3/name 0040.pdf")
----------
readarray -t sortedfilearr < <(printf '%s\n' "${filearray[@]}" | awk -F'/' '
BEGIN{PROCINFO["sorted_in"]="@val_num_asc"}
{ a[$0]=$NF }
END{ for(i in a) print i}')
The output:
echo "${sortedfilearr[*]}"
dir2/name 0003.pdf dir1/name 0010.pdf dir3/name 0040.pdf
Accessing single item:
echo "${sortedfilearr[1]}"
dir1/name 0010.pdf
That assumes that no file path contains newline characters. Note that the numerical sorting of the values in `@val_num_asc` only applies to the leading numerical part of the key (none in this example) with fallback to lexical comparison (based on `strcmp()`, not the locale's sorting order) for ties.