The OP example also sets the values to a single scalar variable.
Array syntax is "
array=( <wordlist> )"
Notice too that the
globbing patterns in the OP example are expanded and passed to
ls before it's executed, so you're really just using it as a superfluous "print" command (and which would be subject to wordsplitting if used inside array brackets).
You can simply use the globs directly to set the array instead:
Code:
filearr=( file* doc* )
for f in "${filearr[@]}"; do
echo "This is file: $f"
done
Finally, since environment variables are generally all upper-case, it's good practice to keep your own user variables in lower-case or mixed-case to help differentiate them.