In bash, brace expansion is the first step attempted so, at that point, $length
will not have been substituted.
The manpage for bash states clearly:
A sequence expression takes the form {x..y[..incr]}, where x and y are either integers or single characters ...
There are a number of possibilities, such as using:
pax> for i in $(seq 0 $length) ; do echo $i ; done
0
1
2
3
though that may give you a large command line if length
is massive.
Another alternative is to use the C-like syntax:
pax> for (( i = 0; i <= $length; i++ )) ; do echo $i; done
0
1
2
3