Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 27 Apr 2010 22:33:52 +0200
From:      Jilles Tjoelker <jilles@stack.nl>
To:        Andrey Chernov <ache@nagual.pp.ru>, src-committers@FreeBSD.ORG, svn-src-all@FreeBSD.ORG, svn-src-head@FreeBSD.ORG
Subject:   Re: svn commit: r207206 - head/bin/sh
Message-ID:  <20100427203352.GB7165@stack.nl>
In-Reply-To: <20100427035224.GA87611@nagual.pp.ru>
References:  <201004252043.o3PKhJi7065713@svn.freebsd.org> <20100427035224.GA87611@nagual.pp.ru>

next in thread | previous in thread | raw e-mail | index | archive | help
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



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20100427203352.GB7165>