unix shell programming question

Conor P. Cahill cpcahil at virtech.uucp
Tue Feb 27 01:53:23 AEST 1990


In article <504 at lkbpyr.UUCP> jonas at lkbpyr.UUCP (Jonas Heyman) writes:
>echo $str1        #This is OK   "string 1"
>echo $str2 	  #This is OK   "string 2"
>
>for loop in 1 2
>do
>	aa=$str$loop     #Here I want "string 1" and "string 2"
	^^^^^^^^^^^

>	echo $aa
>
>	echo $str$loop   #Here I want "string 1" and "string 2"
        ^^^^^^^^^^^^^^
>done

Replace the indicated lines with:

	eval aa=\$str$loop     #Here I want "string 1" and "string 2"

and

	eval echo \$str$loop   #Here I want "string 1" and "string 2"

respectively, and you will get the output you desire.  Eval just tells
the shell to read the arguments as input and execute them.  this
causes the rest of the line to be scanned twice.  On the first scan, the
\$str is converted to $str and the $loop is converted to 1 or 2. The
second scan interprets the $str1 or $str2

-- 
+-----------------------------------------------------------------------+
| Conor P. Cahill     uunet!virtech!cpcahil      	703-430-9247	!
| Virtual Technologies Inc.,    P. O. Box 876,   Sterling, VA 22170     |
+-----------------------------------------------------------------------+



More information about the Comp.unix.questions mailing list