The expression
ls {*.xml,*.txt}
results in Brace expansion and shell passes the expansion (if any) to ls
as arguments. Setting shopt -s nullglob
makes this expression evaluate to nothing when there are no matching files.
Double quoting the string suppresses the expansion and shell stores the literal contents in your variable name
(not sure if that is what you wanted). When you invoke ls
with $name
as the argument, shell does the variable expansion but no brace expansion is done.
As @Cyrus has mentioned, eval ls $name
will force brace expansion and you get the same result as that of ls {*.xml,*.txt}
.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…