Re: svn commit: r207206 - head/bin/sh

[ Available lists | Index of svn-src-all | Month of Apr 2010 | Week of 27 Apr 2010 | Raw email | View thread | Wrap long lines | Reply | Tag ]
From
Jilles Tjoelker <jilles@stack.nl>
Date
27 Apr 2010 20:40:50
Subject
Re: svn commit: r207206 - head/bin/sh
Message-ID
20100427203352.GB7165@stack.nl


[ Hide this part ]
On Tue, Apr 27, 2010 at 07:52:25AM +0400, Andrey Chernov wrote:
> On Sun, Apr 25, 2010 at 08:43:19PM +0000, Jilles Tjoelker wrote:
> > Author: jilles
> > Date: Sun Apr 25 20:43:19 2010
> > New Revision: 207206
> > URL: http://svn.freebsd.org/changeset/base/207206
> >
> > Log:
> > sh: Use stalloc for arith variable names.
> >
> > This is simpler than the custom memory tracker I added earlier, and is also
> > needed by the dash arith code I plan to import.

> Just wonder, do you have plans to implement ${!variable} sometimes?
> This bashism is very useful:

> VAR_a1=foo
> x=VAR_a1
> echo ${!x}

This doesn't do anything you cannot do with eval:
eval echo \$$x

Furthermore, note that ksh93 and recent versions of mksh have almost the
opposite meaning for ${!variable}, for example
VAR_a1=foo
typeset -n x=VAR_a1
echo $x:${!x}
which prints foo:VAR_a1
(Explanation: typeset -n creates a "nameref" which redirects assignment
and expansion to the variable name specified in the initial assignment.
${!X} expands to the name of the variable which is X unless X is a
nameref.)

We do have the setvar builtin for the reverse operation, inherited from
the original ash, but I wouldn't have added this as it is likewise
easily done with eval. The list assignment syntax
setvar var word1 ... wordN
has never been implemented, and I don't think it adds anything above
ksh's syntaxes
var=(word1 ... wordN)
and
set -A var word1 ... wordN

--
Jilles Tjoelker


Elapsed time: 0.133 seconds