From 8a03f451b2669faf4fa98b99978e8ba570948613 Mon Sep 17 00:00:00 2001 From: John D Pell Date: Sun, 19 Sep 2021 01:26:02 -0700 Subject: [PATCH] lib/helpers: simplify `_command_exists()` and `_binary_exists()` Remove subshell and just use a regular `if` --- lib/helpers.bash | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) mode change 100644 => 100755 lib/helpers.bash diff --git a/lib/helpers.bash b/lib/helpers.bash old mode 100644 new mode 100755 index 61705a04..fbc6aa88 --- a/lib/helpers.bash +++ b/lib/helpers.bash @@ -23,7 +23,13 @@ function _command_exists () _example '$ _command_exists ls && echo exists' _group 'lib' local msg="${2:-Command '$1' does not exist!}" - type "$1" &> /dev/null || (_log_warning "$msg" && return 1) ; + if type -t "$1" &> /dev/null + then + return 0 + else + _log_warning "$msg" + return 1 + fi } function _binary_exists () @@ -34,7 +40,13 @@ function _binary_exists () _example '$ _binary_exists ls && echo exists' _group 'lib' local msg="${2:-Binary '$1' does not exist!}" - type -P "$1" &> /dev/null || (_log_warning "$msg" && return 1) ; + if type -P "$1" &> /dev/null + then + return 0 + else + _log_warning "$msg" + return 1 + fi } function _completion_exists ()