nested loops

Gilles Courcoux gilles at pase60.Convergent.Com
Sat Aug 11 02:15:51 AEST 1990


In article <4103 at herbie.misemi> you wrote:
>The problem lies in the  $`echo $i` statment

Right, double variable expansion like that is resolved through the use
of the eval(1) command as in :
	eval echo '$'$i

When the shell read the command, it expands it into 
	eval echo $them			# the first time !

and then eval(1) do his job : evaluating its arguments, including
variables expansion and then execute the command which is by now :
	echo one two three

The echo(1) command is needed because eval(1) then exec(2)utes its
first argument.

Your script become :

this="one two three"
that="four five six seven"
them="eight nine ten"
all="this that them"
#
for i in $all
do
	for j in `eval echo '$'$i`
	do
	echo $i $j
	done
done

Have a nice day,

Gilles Courcoux                        E-mail: sun!pyramid!ctnews!pase60!gilles
Unisys Network Computing Group         Phone:  (408) 435-7692



More information about the Comp.unix.wizards mailing list