In bash
, brace expansion happens before parameter expansion. The result is that {$FIRSTLETTER..$LASTLETTER}
isn't subject to brace expansion, because it's not a valid sequence expression:
A sequence expression takes the form {x..y[..incr]}, where x and y are
either integers or single characters
Only then does the literal string undergo parameter expansion, resulting in the single word {a..b}
.
In zsh
, brace expansion occurs after several other types of expansion, include parameter expansion, have occurred. Thus, {$FIRST_LETTER..$LAST_LETTER}
expands to {a..b}
, which then undergoes brace expansion to produce a b
.
The end result is that what you are doing should work in zsh
, but not in bash
. Further, short of using eval
, there is no way to do what you want in bash
.
for x in $(eval "echo {$FIRSTLETTER..$LASTLETTER}")
Keep in mind that this is fragile, and requires you to be very sure that the two parameters can only expand to single letters each.