Path: utzoo!mnetor!uunet!seismo!esosun!cogen!alen From: alen@cogen.UUCP (Alen Shapiro) Newsgroups: comp.unix.wizards Subject: Re: Building Variable Names in Bourne Shell Message-ID: <430@cogen.UUCP> Date: 23 Mar 88 22:47:41 GMT References: <12565@brl-adm.ARPA> Reply-To: alen@cogen.UUCP (Alen Shapiro) Organization: Cogensys, LaJolla, Calf. Lines: 55 In article <12565@brl-adm.ARPA> kevinc@bearcat.lim.tek.com (Kevin Cosgrove 627-5212) writes: >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. Nice exercise - try this. BTW /bin/calendar is a GREAT crib sheet for such things #!/bin/sh onestring="A" twostring="B" threestring="C" for string in one two three do var="a=\$${string}string" eval $var echo ${string}string = $a done --alen the Lisa slayer (it's a long story) In te re st in g li ne fi ll er go es he re