Subject: Re: Bourne shell question
To: Daniel Eggert <danieleggert@mac.com>
From: Jeremy C. Reed <reed@reedmedia.net>
List: netbsd-help
Date: 12/19/2002 08:23:17
On Thu, 19 Dec 2002, Daniel Eggert wrote:

> In my shell script I have two variables. Something like this:
> 	partitions="ld0a ld0b ld1a"
> 	paths="/a /b /c"
> Now I want to loop through these and access
> 	'ld0a' with '/a'
> 	'ld0b' with '/b'
> 	'ld1a' with '/c'
> Is there any easy / clever way to do this in /bin/sh?

Use /bin/ksh (because it supports arrays).

set -A partitions ld0a ld0b ld1a
set -A paths /a /b /c

index=0
while [ $index -lt ${#partitions[@]} ] ; do
  echo \'${partitions[$index]}\' with \'${paths[$index]}\'
  let index=index+1
done

   Jeremy C. Reed
   http://bsd.reedmedia.net/