Subject: Re: replacement for which(1)
To: Thor Lancelot Simon <tls@rek.tjls.com>
From: Simon J. Gerraty <sjg@crufty.net>
List: tech-userlevel
Date: 04/01/2004 18:20:16
>> The existing which(1) is inappropriate due since its a csh script
>> and follows the wrong semantics for the above.
>Yes, but it follows the _appropriate_ semantics for which(1), which is,
>very explicitly, supposed to find the binary *where csh, invokved
Yes I know, and I agree - its just that it isn't very useful/interesting.
That's why while I'm not advocating replacing which(1) - since by definition
you can't, I'm saying that that does not mean one must be limited to using it.
>> Shell builtins like type, whence etc, are also not very useful since every
>> shell has a different one, and not all of them do just the above.
>That's not so. POSIX-conformant Bourne shells have the same one, which
>does what you want; we ship two shells that are intended to be POSIX-
Er, not quite.
$ type telnet
telnet is an alias for w_telnet
that does not meet the requirement I stated.
Besides, I think I used the word portable somewhere.
HP-UX at least, has a /bin/sh which still has all the early 80's era
bugs - so you cannot write a portable script which relies on POSIX behavior.
As I said, the only sane solution is to use a simple shell function
(er not that you can use those very safely with HP-UX's /bin/sh ;-)
>it anyway, so the fact that you have to use "which" instead of "type"
>is basically irrelevant.
Does "type" work with SysV R2's /bin/sh? - genuine question - I no longer
have access to such a beast (that's about what HP-UX's sh is).
My point was that a an external command solution that only works on
NetBSD isn't a solution, since scripts which are NetBSD specific
can just use "type" as you say, and portable scripts need a different
solution anyway.
FWIW I've found the Which() function I mentioned DTRT on all flavors of
SunOS, HP-UX, IRIX, *BSD, Linux, AIX, OSF, ....
and just about everything I've had to work on.
--sjg