From 0459e0e45036aeb6c6e23a346019371002411eb3 Mon Sep 17 00:00:00 2001 From: bol-van Date: Tue, 8 Aug 2023 10:47:01 +0300 Subject: [PATCH] do not use possibly absent 'which' command --- common/base.sh | 14 ++++++++++++++ install_bin.sh | 6 ++---- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/common/base.sh b/common/base.sh index bba133a..0d9cbef 100644 --- a/common/base.sh +++ b/common/base.sh @@ -1,3 +1,17 @@ +which() +{ + # on some systems 'which' command is considered deprecated and not installed by default + # 'command -v' replacement does not work exactly the same way. it outputs shell aliases if present + # $1 - executable name + local IFS=: + for p in $PATH; do + [ -x "$p/$1" ] && { + echo "$p/$1" + return 0 + } + done + return 1 +} exists() { which "$1" >/dev/null 2>/dev/null diff --git a/install_bin.sh b/install_bin.sh index ef1cd99..31b5fce 100755 --- a/install_bin.sh +++ b/install_bin.sh @@ -5,10 +5,8 @@ EXEDIR="$(cd "$EXEDIR"; pwd)" BINS=binaries BINDIR="$EXEDIR/$BINS" -exists() -{ - which "$1" >/dev/null 2>/dev/null -} +ZAPRET_BASE="$EXEDIR" +. "$ZAPRET_BASE/common/base.sh" check_dir() {