Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!convex!texsun!letni!mic!ernest!shibaya!afc From: afc@shibaya.lonestar.org (Augustine Cano) Newsgroups: comp.unix.shell Subject: sh loop variable and "double indirection" Message-ID: <1991Jan27.044258.18779@shibaya.lonestar.org> Date: 27 Jan 91 04:42:58 GMT Organization: Multidisciplinary Designs Unlimited Lines: 51 I am trying to specify (at run time) an upper limit for a loop in a shell script. In pseudo-code the ideal would be something like this: read i for 0 to i do ... done The closest I've come to this is what follows: echo "enter upper limit" read limit for i in 0 1 2 3 4 5 6 7 8 9 do # some processing that involves $i goes here if test $i -ge $limit-1 ; then # NOTE: for i=3, I want iterations 0,1,2 break fi done Not very elegant since a limit of 10 iterations is hard-wired. Can anybody think of a more concise way to do this? Using PERL is not an option, this must be portable sh code. The next problem is the thorny one. Some shell variables having been previously set up, say: var0=REAL_VALUE0 var1=REAL_VALUE1 var2=REAL_VALUE2 var3=REAL_VALUE3 var4=REAL_VALUE4 I want to manipulate variable names inside the above loop such that I could display the "REAL VALUEx" based on the current value of $i. At the prompt, with the above variables initialized, echo $var0, echo $var1, etc... yield the expected results. When I put echo $var$i in the loop, it doesn't work. Other variations, such as echo $"$var$i", etc... don't work either. How can this be done? How is it possible to make sh group $var and $i first and then get the real value of the variable that results from combining the 2 strings? Any help will be greatly appreciated!!! I'll summarize e-mail responses. Thanks in advance. -- Augustine Cano INTERNET: afc@shibaya.lonestar.org UUCP: ...!{ernest,egsner}!shibaya!afc