0

From https://unix.stackexchange.com/a/7739/674, why does parameter expansion happen before brace expansion in the following example?

eval rm foo.{$ext0..$extN}
3

It's doing a no-op brace expansion first (expanding to what you started with), then parameter expansion, then brace expansion within "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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.