Building Variable Names in Bourne Shell

Kevin Cosgrove 627-5212 kevinc at bearcat.lim.tek.com
Tue Mar 22 16:31:43 AEST 1988


Anyone know how to build *accessible* variable names on the fly in Bourne
shell?  Below is a do nothing script which, I hope, demonstrates what I
want to do.

#!/bin/sh
onestring="A"			# set the values of arbitrary strings
twostring="B"
threestring="C"
for string in one two three	# loop thru string sets
do
   var="${string}string"	# var contains the name of the string
				# I wish to get access to

   echo "\$$var = ${var}"	# how do I get the contents of the string
				# "pointed to" by var?
   echo
done

Yes, I know there are lots of other shells and/or languages which make
the above easy to do, but I'm trying to patch existing scripts, and this
would make it much easier to do.


Disclaimer:  donning fire resistant suit now...
__________________________________________________________________________

	Kevin Cosgrove			Tektronix, Inc.
	(503)-627-5212			PO Box 500, M/S 47-092
	kevinc at bearcat.LIM.TEK.COM	Beaverton, OR  97077
__________________________________________________________________________



More information about the Comp.unix.wizards mailing list