从https://unix.stackexchange.com/a/7739/674,为什么在下面的示例中参数扩展发生在大括号扩展之前?
eval rm foo.{$ext0..$extN}
答案1
它首先进行无操作大括号扩展(扩展到您开始的内容),然后进行参数扩展,然后在“eval”内进行大括号扩展:
# No-op brace expansion example:
echo foo.{not..understood}
# See: foo.{not..understood}
ext0=10
extN=20
# Parameter expansion
echo foo.{$ext0..$extN}
# See: foo.{10..20}
# Final brace expansion
eval echo foo.{$ext0..$extN}
# See: foo.10 foo.11 foo.12 foo.13 foo.14 foo.15 foo.16 foo.17 foo.18 foo.19 foo.20
# Now if you want to have fun with it (each eval unwraps one level of escapes)
eval eval eval eval echo foo.{\\\\\\\$ext0..\\\\\\\$extN}
# See: foo.10 foo.11 foo.12 foo.13 foo.14 foo.15 foo.16 foo.17 foo.18 foo.19 foo.20