indirect shell-vars

Chuck Karish karish at forel.stanford.edu
Wed Sep 13 07:18:24 AEST 1989


In article <627 at targon.UUCP> ruud at targon.UUCP (Ruud Harmsen) wrote:
 >I'm looking for a way to reference a variable in the Bourne-shell,
 >whose name is given in another variable.  I found the following solution
 >using a sub-shell myself, but it seems rather clumsy:.

 >export x1; x1=one
 >export x2; x2=two
 >echo which var\?
 >read xx
 >sh -c "echo \$x`echo $xx`"

eval echo \$x$xx

By escaping some of the `$' signs, you can cause eval to expand the
variables in the desired order.

	Chuck Karish		karish at mindcraft.com
	(415) 493-9000		karish at forel.stanford.edu



More information about the Comp.unix.questions mailing list