The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Advanced & Expert Users
Google UNIX.COM



View Single Post in UNIX Forums - Click on the Thread or Permalink to View Entire Thread -->
  #3 (permalink)  
Old 08-23-2007
manas_ranjan's Avatar
manas_ranjan manas_ranjan is offline
Registered User
 

Join Date: Jul 2007
Location: PUNE
Posts: 171
Quote:
Originally Posted by Perderabo View Post
Code:
$ cat arrayloop
#! /usr/local/bin/bash

abc=(a b c)
def=(d e f)
ghi=(g h i)
array1=(abc def ghi)
cnt=0
total_Array=${#array1[*]}
no_loop_thru=${#abc[*]}

while [ $cnt -lt $total_Array ] ; do
        srch_fld=${array1[$cnt]}
        j=0
        while [ $j -le $no_loop_thru ] ; do
                eval var1=\${$srch_fld[$j]}
                echo ${var1}
                ((j=j+1))
        done
        ((cnt=cnt+1))
done
exit 0
$ ./arrayloop
a
b
c

d
e
f

g
h
i

$

hey i got alternative method as follows,
while [ $j -le $no_loop_thru ] ; do
var1=$srch_fld[$j]
echo ${!var1}
((j=j+1))
done
Reply With Quote