Path: utzoo!utgpu!news-server.csri.toronto.edu!rutgers!apple!voder!pyramid!infmx!housed From: housed@infmx.informix.com (Darryl House) Newsgroups: comp.unix.internals Subject: re: puzzle Message-ID: <1990Nov27.003659.3521@informix.com> Date: 27 Nov 90 00:36:59 GMT Sender: uunet!infmx.informix.com!housed Distribution: usa Organization: Informix Software, Inc. Lines: 67 Originator: housed@godzilla *OOPS* - I included the wrong file in the last message, here is the right one. Sorry if this causes any confusion... The following is a Bourne shell script that illustrates what I am trying to do: set a shell variable that contains the contents of another one that is referred to by concatenating two others. Sufficiently confusing? Yeah, I thought so, too. Note that I don't really want to keep track of how many iterations there are, that'd be absurdly simple to track. The application is too complex to describe here, but I did fix the problem by using a C program rather than a shell script. I just thought that this was a very interesting puzzle. -------------------------------------------------------- #! /bin/sh # what I want is to be able to set # the ITERATION variable to be the expanded # version of $PREFIX$SUFFIX, i.e. the first iteration # would be the contents of $firsttime, the second # would be the contents of $secondtime. The following # code gives me errors, and everything I try either gets # the same substitution failure or just echoes the name # of the variable, i.e. ($firsttime and $secondtime). echo firsttime="first_time" secondtime="second_time" PREFIX_WORDS="first second" SUFFIX="time" for PREFIX in $PREFIX_WORDS do # the following line doesn't work, but # sort of illustrates what I want to do. # I want this to be ITERATION=$firsttime the first time # through and ITERATION=$secondtime the second time. ITERATION=${$PREFIX$SUFFIX} echo 'Iteration is $ITERATION' done echo exit 0 -------------------------------------------------------- Required output: prompt% program_name Iteration is first_time Iteration is second_time prompt% Any hints you can offer will be greatly appreciated. Thank you, and have a nice day!