Subject: Re: "for" behaviour in /bin/sh
To: I presume I need no introduction. <greywolf@starwolf.starwolf.com>
From: Johnny C. Lam <lamj@stat.cmu.edu>
List: current-users
Date: 07/13/1998 11:18:58
> I'd say that NetBSD's sh doesn't catch this is a bug, but only by the
> "virtue" that no other Bourne Shell that I've seen behaves thusly.
>
> --*greywolf;
So is the "correct" thing to do to replace
for f in ${LIST}; do
echo $f
done
with
for f in ${LIST} ""; do
if [ X"$f" != X"" ]; then
echo $f
fi
done
?? Is there a better way to do this?
I notice that /bin/sh in FreeBSD and OpenBSD behave like NetBSD's.
I discovered this variance in behaviour of NetBSD's /bin/sh when I
ported our pkgsrc system to HP-UX. bsd.pkg.mk relies on the /bin/sh
accepting an empty list in the for loop for trivial cases. [ As an
aside, in bsd.pkg.mk, we often use ".if defined(FOO)" when we really
mean to say ".if !emtpy(FOO)" .]
--
Johnny C. Lam
Department of Statistics lamj@stat.cmu.edu
Carnegie Mellon University http://www.stat.cmu.edu/~lamj/
@>---`---,----