Article View: comp.unix.shell
Article #1841Re: puzzle
From: John R. Levine
Date: Tue, 27 Nov 1990 04:39
Date: Tue, 27 Nov 1990 04:39
24 lines
1143 bytes
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!PostmasterShow 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>