From df3d04affac9ec8cddea62a140cf6f3216094d6f Mon Sep 17 00:00:00 2001 From: ng0 Date: Mon, 16 Dec 2019 11:50:31 +0000 Subject: switch existence over to 'type', add shell check for type built-in support. --- sh/lib.sh/existence.sh | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'sh') diff --git a/sh/lib.sh/existence.sh b/sh/lib.sh/existence.sh index a888dee..cddc3d6 100644 --- 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 } -- cgit v1.2.3