nested loops

iccad adley at herbie.misemi
Fri Aug 10 05:17:28 AEST 1990


Hi,
We are trying to write a Bourne shell script that includes two 
nested loops as follows

!# /bin/sh
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 $`echo $i`
do
echo $i $j
done
done


we want (and expected!) the output:
this one
this two
this three
that four
that five
that six
that seven
them eight
them nine
them ten

The problem lies in the  $`echo $i` statment
the `echo $i` preforms as expected and the result is one of this,
that, or them
the $ infront of this statment however is taken as a literal $
and does not return the value of the variable this or that or them
instead it returns $this or $that or $them.

Does anybody know why this happens or how we can get the results 
that would be expected here (with the exception of doing it in a 
C shell or in a C program).

Thanks.



More information about the Comp.unix.wizards mailing list