Please note that nodir posted some links referencing the concepts they introduced and there are examples of those concepts in those links.
Unsure if I had offered this link before in one of your other questions,
My Bash script blog this has some useful tips for debugging and various techniques to use when developing bash scripts.
There are some code examples in that blog, but the code is specific to my examples and activity I'm discussing.
For now, the recommendation to stay away from using the output of ls is a good one. Myself I'd find files and use the output of the find command to accomplish my next step actions.
Also, in general I find that file names with special characters, spaces, or added extensions, like .tar.gz, or joes file.xlsx will cause issues with bash scripts or commands unless they are properly coded. I find using double quotes around wildcard or other types of special characters are important.