The problem is that brace expansion occurs before variable expansion:
Code:
$ man bash:
EXPANSION
...
The order of expansions is: brace expansion, tilde expansion, parame-
ter, variable and arithmetic expansion and command substitution (done
in a left-to-right fashion), word splitting, and pathname expansion.
Inside of the braces, when brace expansion occurs, there is the string of characters "$FILES", and this matches no file names. What remains is:
which is dutifully variable expanded:
Code:
ls -l /dir1/dir2/dir3/file1,file2,file3
and of course you see the consequences. In these situations,
eval is your friend:
Code:
eval ls -l $DIR/$FILE