puzzle
John R. Levine
johnl at iecc.cambridge.ma.us
Tue Nov 27 15:39:32 AEST 1990
In article <1990Nov27.003659.3521 at 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 at iecc.cambridge.ma.us, {spdcc|ima|world}!iecc!johnl
More information about the Comp.unix.shell
mailing list