On Wed, Jun 23, 2010 at 03:27:28PM -0500, Peng Yu wrote:
> #for i in {0..${#parameter}};
This doesn't work. The parser does things in a very specific order.
Brace expansion is done before parameter expansion. The parser sees
0..$ and that isn't a legitimate brace expansion range, so it doesn't
perform the expansion; it leaves it alone. Then the parameter expansion
occurs, and the ${#parameter} is replaced.
If you REALLY MUST use brace expansion, you'll have to wrap the whole
thing in eval. I'd recommend using a for loop instead:
for ((i=0; i<=${#parameter}; i++))
Or if you require (or simply want) the ${#parameter} part to be evaluated
only one time:
n=${#parameter}
for ((i=0; i<=n; i++))