commit df3d04affac9ec8cddea62a140cf6f3216094d6f parent ba139160511026f08dd4611dc689ee5a211febf5 Author: ng0 <ng0@n0.is> Date: Mon, 16 Dec 2019 11:50:31 +0000 switch existence over to 'type', add shell check for type built-in support. Diffstat:
| M | sh/lib.sh/existence.sh | | | 16 | ++++++++++++---- |
1 file changed, 12 insertions(+), 4 deletions(-)
diff --git a/sh/lib.sh/existence.sh b/sh/lib.sh/existence.sh @@ -18,10 +18,18 @@ # # SPDX-License-Identifier: 0BSD -# there is a function used in curl to replicate which(1), but -# it uses too many other tools. this one uses command and in -# gnunet so far has no reports about failures. +errmsg='' + +# Check if shell supports builtin 'type'. +if test -z "$errmsg"; then + if ! (eval 'type type') >/dev/null 2>&1 + then + errmsg='Shell does not support type builtin' + exit 1 + fi +fi + existence() { - command -v "$1" >/dev/null 2>&1 + type "$1" >/dev/null 2>&1 }