🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.unix.shell
Article #1841

Re: puzzle

#1841
From: John R. Levine
Date: Tue, 27 Nov 1990 04:39
24 lines
1143 bytes
In article <1990Nov27.003659.3521@informix.com> you write:
>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?

No more confusing than any other Bourne shell string munging.  The
trick is to build up the assignment string and then use eval to rescan it:

# Prints:
# Iteration is first_time
# Iteration is second_time

firsttime="first_time" secondtime="second_time"

PREFIX_WORDS="first second" SUFFIX="time"

for PREFIX in $PREFIX_WORDS
do
	eval ITERATION=$\{$PREFIX$SUFFIX\}
	echo "Iteration is $ITERATION"
done

Regards,
John Levine, johnl@iecc.cambridge.ma.us, {spdcc|ima|world}!iecc!johnl
Technical Details
Message-ID: <9011262339.AA26172@iecc.cambridge.ma.us>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!rutgers!cs.utexas.edu!uunet!world!iecc!Postmaster

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!rutgers!cs.utexas.edu!uunet!world!iecc!Postmaster
From: johnl@iecc.cambridge.ma.us (John R. Levine)
Newsgroups: comp.unix.shell
Subject: Re: puzzle
Message-ID: <9011262339.AA26172@iecc.cambridge.ma.us>
Date: 27 Nov 90 04:39:32 GMT
Sender: Postmaster@iecc.cambridge.ma.us
Organization: I.E.C.C.
Lines: 24
In-Reply-To: <1990Nov27.003659.3521@informix.com>