[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: The usage of {0..${#parameter}}

From: Greg Wooledge
Subject: Re: The usage of {0..${#parameter}}
Date: Wed, 23 Jun 2010 16:41:48 -0400
User-agent: Mutt/

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:

  for ((i=0; i<=n; i++))

reply via email to

[Prev in Thread] Current Thread [Next in Thread]