Path: utzoo!attcan!uunet!bu.edu!snorkelwacker!usc!cs.utexas.edu!helios!cs.tamu.edu From: skdutta@cs.tamu.edu (Saumen K Dutta) Newsgroups: comp.unix.wizards Subject: Re: nested loops Message-ID: <7318@helios.TAMU.EDU> Date: 10 Aug 90 06:23:53 GMT References: <4103@herbie.misemi> Sender: usenet@helios.TAMU.EDU Organization: Computer Science Department, Texas A&M University Lines: 66 In <4103@herbie.misemi> article adley@herbie.misemi writes: -> ->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. -> If you modify the code in the following way it will work. I bet there must be a simpler way of doing this: #! /bin/sh this="one two three" that="four five six seven" them="eight nine ten" all="this that them" # for i in $all do k='eval echo $`echo $i`' for j in `eval $k` do echo $i $j done done -- _ ||Internet: skdutta@cssun.tamu.edu ( /_ _ / --/-/- _ ||Bitnet : skd8107@tamvenus.bitnet __)_/(_____(_/_(_/_(_(__(_/_______ ||Uucp : uunet!cssun.tamu.edu!skdutta .. ||Yellnet: (409) 846-8803