Re: eval

2011-05-03 Thread Jonathan Nieder
Hi Rafael,

Rafael Fernandez wrote:

> set -- a b c d e f g h i j k l m n o p q r s t u v w x y z
> i=1
> eval echo '$'$i # outputs an expected 'a'
> i=10
> eval echo '$'$i # outputs 'a0'; expected 'j'
> i=11
> eval echo '$'$i # outputs 'b1'; expected 'k'

Have you tried

eval "echo \${$i}"

?



Re: eval

2011-05-03 Thread DJ Mills
On Tue, May 3, 2011 at 10:41 PM, Jonathan Nieder  wrote:

> Hi Rafael,
>
> Rafael Fernandez wrote:
>
> > set -- a b c d e f g h i j k l m n o p q r s t u v w x y z
> > i=1
> > eval echo '$'$i # outputs an expected 'a'
> > i=10
> > eval echo '$'$i # outputs 'a0'; expected 'j'
> > i=11
> > eval echo '$'$i # outputs 'b1'; expected 'k'
>
> Have you tried
>
>eval "echo \${$i}"
>
> ?
>
> That has nothing to do with eval.  The only way to explicitly expand a
positional
parameter > 9 is to use braces, echo "${10}"


Re: eval

2011-05-03 Thread Jonathan Nieder
Rafael Fernandez wrote:

> Thanks, I wasn't aware that positional parameters greater than nine have to
> be enclosed in brackets.

No prob.  The manpage says

When a positional parameter consisting of more than a single
digit is expanded, it must be enclosed in braces (see
EXPANSION below).

If you have an idea for making this clearer (maybe somewhere in the
info documentation) I imagine it would be welcome.

For the future, the sh specification at
http://www.unix.org/2008edition/ (free registration required) is also
very useful for tracking down how a shell might understand a script.