The links I gave, and other related ones at that site, go into a lot of detail about your various options. Reading them should give you some clues about ways to proceed.
The main problem with storing lists in a scalar variable is in reliably reading them back out again. Arrays make this easy by storing each value in a separate memory space, but regular variables don't.
The only way to do it semi-safely (without going into major gymnastic contortions, at least) is to select a separator character that is unlikely to ever be part of a filename, and set your
IFS variable to word-split only on it. The null character would be perfect, but unfortunately it's the one character that variables cannot store, and they will be silently discarded if you attempt to do so (actually, it's the fact that they can never appear in a variable or filename that makes them the perfect separator). But tools like
find can generate lists using them, and those can be processed dynamically with a
while+read loop.
The easiest separator to use is actually the simple newline, but it, like all other characters, depends on the assumption that none of the filenames will ever contain one. If you don't have arrays, that's about all you can do.
How can I find and deal with file names containing newlines, spaces or both?
http://mywiki.wooledge.org/BashFAQ/020
[ Edit: Come to think of it, there is one "array" available to even POSIX shells, and that's the set of input parameters ("
$@"). Section 4 of the array link I gave above describes how to use it. ]
See here too for more on how the shell does word-splitting and argument processing. This is a vital concept in scripting, so learn it well!
http://mywiki.wooledge.org/Arguments
http://mywiki.wooledge.org/WordSplitting
http://mywiki.wooledge.org/Quotes
Actually, nothing you've posted so far seems to need storing the filenames themselves in a variable anyway. As I said before, all it requires is looping over the files and testing each one in turn, then printing out the final tallies. Unless there's something to the assignment you haven't mentioned yet.
It would also help to clarify what shell(s) you are using/are allowed to use, as ones like
bash and
ksh have features not available to POSIX shells that make these things easier and safer to do (arrays are just one example).