If echo $filesToDelete prints the list of elements, it's not an array; if it were an actual array that would only print the first element. I'm pretty sure what you actually have is just a string with spaces separating the elements.
The immediate problem you have is that you've put the variable (/array) reference in single-quotes, and the shell doesn't perform variable expansion inside single-quotes. In fact, it doesn't do any parsing of the contents of single-quotes (except to look for the close quote). In the shell, there are 3 main quoting contexts:
- Inside single quotes, no interpretation (of variable references, wildcards, etc) is performed at all.
- Inside double-quotes, variable references (and other things starting with
$) are done, as are backquoted commands and some escape (\) sequences. Once variables (etc) have been substituted, no parsing is done on the substituted values (which is almost always what you want).
- When unquoted, variable references (and many other things) are done, and then the substituted values are split into words (separated by spaces and other whitespace), and any wildcards are substituted.
Since filesToDelete is apparently a plain string with spaces separating the filenames, you need to refer to it unquoted to get it split into words. But this can fail catastrophically if any of the filenames contain spaces and/or wildcards. My standard example of this was Apple's installer for iTunes 2.0, which contained a command to delete the old version; something like rm -R $1. If the old version was located at e.g. /Volumes/Data 2/Applications/iTunes.app, this would delete the entire contents of /Volumes/Data, then complain that 2/Applications/iTunes.app didn't exist. Apple released version 2.0.1 very very quickly after that, and the only change was to add double-quotes around the reference to $1. IIRC they also wound up buying data recovery software for some of their customers.
If you need to store multiple filenames safely, use a real array. Create it with something like filesToDelete=(value1 value2 value3 value4) (note that word splitting and wildcard expansion is performed here as well, so wrap any variable references in double-quotes). Then use it with something like:
for i in "${filesToDelete[@]}"; do
rm "$i"*.*
done
Note that in the rm command, I put double-quotes around the variable reference, but not the parts that need to be interpreted as wildcards. (Also, in the shell a semicolon is not needed at the end of a line, so I left it off.)