Mike Frysinger wrote:
[...]
which is pretty well ported ... OS X (Darwin), BSD, Linux have it by
default ...
True. I looked for a machine w/o it and couldn't find one. I do
recall that we had one where it wasn't available (AIX 4.2 maybe?)
In any case, it's not in POSIX.
(Looking some more... Ah, found one: z/OS UNIX System Services.)
afaik, which should only error under really bad circumstances, so something
like this should work:
which_binary=`which which 2>/dev/null`
test -z "$which_binary" && echo no which available
i guess if you're going to be really super anal about it, you'd wrap the whole
thing in a local function:
function my_which() {
if test -z "$which_binary" ; then
... your workaround here ...
My point was that if I go to the trouble of implementing a workaround
for a missing which I might as well use it instead and save myself the
effort of maintaining two solutions.
else
$which_binary "$@"
fi
}
note that you cant rely on exit status on which, just output ... stupid OS X
ships a broken which that always exits 0 even if the specified utility isnt
found
POSIX should really add which as a requirement. It's essential,
non-trivial to work around when it doesn't exist, and widely
implemented.
Martin
_______________________________________________
Help-make mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/help-make