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 17:21:33
> Thanks. You allmost got it. With a bit of debugging I got this:
> 
> #!/bin/sh
> index() {
>      local i=$1
>      shift $i
>      eval echo $i $@ > /dev/null
>      echo $1
> }
> partitions="ld0a ld0b ld1a"
> paths="/a /b /c"
> i=1;
> while
>          p=`index $i $partitions`
>          q=`index $i $paths`
>          [ -n "$p" -a -n "$q" ]
> do
>          echo $p "and" $q
>          i=$(($i+1))
> done
> 
> and it works like a charm!


Yes - I spotted the 'eval' free version just after sending the mail.
(had to go off for a bit).

Of course, if you need it to run on an AT&T /bin/sh you can do:

index()
{
	shift $1
	echo $1
}

set -- x
while
	p=`index $# $partitions`
	q=`index $# $paths`
	[ -n "$aa" -a -n "$bb" ]
do
	echo $p $q
	set -- $* x
done

For some reason (another bug in /bin/sh)
	local i=1
	eval echo \${$i}
doesn't work - ok without the local...

This may be a bug I've introduced :-( the 1.5.1 /bin/sh I have is fine.

	David

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