puzzle

Jonathan Hahn hahn at nas.nasa.gov
Tue Nov 27 13:45:17 AEST 1990


In article <1990Nov27.003659.3521 at informix.com> housed at infmx.informix.com (Darryl House) writes:
>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?

The following script creates a string which accomplishes the
assignment to ITERATION, and calls "eval" to evaluate the string.
BTW, the echo needs double quotes so the value of ITERATION will
be printed.

----------------------------------------------------------------------
	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
----------------------------------------------------------------------

-jonathan hahn
--
hahn at gigantor.nas.nasa.gov				wk: (415) 604-4360
..!ames!amelia!hahn					hm: (408) 736-7014



More information about the Comp.unix.internals mailing list