Subject: Re: CVS commit: pkgsrc/mk
To: Johnny C. Lam <jlam@NetBSD.org>
From: Alistair Crooks <agc@pkgsrc.org>
List: pkgsrc-changes
Date: 05/13/2005 23:39:59
On Fri, May 13, 2005 at 12:23:51PM -0400, Johnny C. Lam wrote:
> I discovered the grep is there to return non-zero if pkg_info doesn't
> output anything because awk will always return zero regardless of
> whether it prints anything or not. If the grep returns non-zero, then
> echoing the default prefix will happen. It's easy to do it all from
> within awk, but I was too lazy to do that last night ;) I guess
> something like the following will achieve the same effect:
>
> awk '{ print $2; exit 0; } END { exit 1; }'
>
> I'll do some tests and tighten up that bit of code after I finish up
> with the new tools framework.
Ah, I see, thanks for the explanation.
How about just getting awk to do all the work, default and all? (The
following is not really tested)
[23:36:59] agc@sys3 ...pkgsrc/graphics/tiff 59 > pkg_info -qp libtool-base | env _DEF_=/usr/pkg2 awk 'BEGIN { p = ENVIRON["_DEF_"] } { if (NF > 0) { p = $2; exit } } END { print p }'
/usr/pkg
[23:37:18] agc@sys3 ...pkgsrc/graphics/tiff 60 > echo "" | env _DEF_=/usr/pkg2 awk 'BEGIN { p = ENVIRON["_DEF_"] } { if (NF > 0) { p = $2; exit } } END { print p }'
/usr/pkg2
[23:37:27] agc@sys3 ...pkgsrc/graphics/tiff 61 >
Regards,
Alistair