thanks!
Darryl House
housed at infmx.informix.com
Wed Nov 28 06:29:29 AEST 1990
My sincerest thanks to all those who replied to my question
about shell variable substitution. As is usually the case,
the answer was plainly visible in the man pages. If my
thank-you letter didn't get to anyone who responded, it is
only because the mail bounced.
A summary:
The question was: how to get a shell variable to contain
the contents of another that is referenced by concatenating
two others. A simple shell script was included that illustrated
the problem. I won't include it here in the interest of
bandwidth conservation.
An abashed thanks also to those who correctly chided that no
shell variable expansion occurs within single quotes. It was
a Monday, after all, when I wrote the fragment within a
mailtool without running it and it was the second attempt at
posting it and it doesn't really have anything to do with
the illustration and I was worried about a bald tire on my
car and I'm left-handed and I promise I won't do it again.
Sheesh! ;-} ;-) :-)
Most of the solutions involved using eval. One of the folks
who replied put it most succinctly when he said
it was "a shell verb that runs a string through the shell
variable substitution logic twice instead of once."
Many people offered variations of the solution, and this
was typical of the solutions using eval:
change
ITERATION=${$PREFIX$SUFFIX}
to
ITERATION="$"$PREFIX$SUFFIX
then change
echo Iteration is $ITERATION
to
ITERATION=`eval "echo $ITERATION"`
echo "Iteration is $ITERATION"
Another interesting solution used grep and sed. Though is the
mildest of cases, I love it when this OS gets really cryptic :-)
ITERATION=`grep $PREFIX$SUFFIX $0 | sed -e "s/$PREFIX$SUFFIX=//" -e 's/"//g'`
Again, thank you very much.
Take care, and have a a nice day!
--darryl
"Although robust enough for general use, adventures into the
esoteric periphery of the C shell may reveal unexpected
quirks." -- /usr/man/man4.03/man1/csh.1
More information about the Comp.unix.internals
mailing list