Subject: Re: Bourne shell question
To: Daniel Eggert <danieleggert@mac.com>
From: David Laight <david@l8s.co.uk>
List: netbsd-help
Date: 12/19/2002 16:18:24
On Thu, Dec 19, 2002 at 05:00:00PM +0100, Daniel Eggert wrote:
> I hope this is not completely OT:
> 
> 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?

how about (untested):

index() {
    local i = $1
    shift
    eval echo $\$i
}

i=1;
while
	p=`index $i $partitions`
	q=`index $i $paths`
	[ -n "$p" -a -n "$q ]
do
	echo $p:$q
done



	David

-- 
David Laight: david@l8s.co.uk