Dan Crosta on 19 May 2005 18:04:32 -0000


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Re: [PLUG] bash, double for


Jeff Abrahamson wrote:

I want to do the following in bash.  I don't see an easy way.  (I see
very complicated ways.)  Anyone see an easy way?

for((n=0; n<10; n++)) and $array; do echo Element $n of array is $array[$n]
done




There's always:

n=0
for val in $array; do
   echo Element $n of array is $val
   n=`echo "$n + 1" | bc`
done

There's also probably a better way to increment $n, but this is the pattern I found first, so I use it.

dsc
___________________________________________________________________________
Philadelphia Linux Users Group         --        http://www.phillylinux.org
Announcements - http://lists.phillylinux.org/mailman/listinfo/plug-announce
General Discussion  --   http://lists.phillylinux.org/mailman/listinfo/plug