From d89b7f93b23abef12953b92330c3c941eab5429e Mon Sep 17 00:00:00 2001 From: orbea Date: Tue, 14 Jan 2020 10:20:07 -0800 Subject: [PATCH] qb: Update the exists function. --- qb/qb.init.sh | 39 +++++++++++++++++++++++---------------- 1 file changed, 23 insertions(+), 16 deletions(-) diff --git a/qb/qb.init.sh b/qb/qb.init.sh index 13b6cf9cc9..db02927296 100644 --- a/qb/qb.init.sh +++ b/qb/qb.init.sh @@ -23,22 +23,29 @@ exists() while [ $# -gt 0 ]; do arg="$1" shift 1 - case "$arg" in ''|*/) continue ;; esac - x="${arg##*/}" - z="${arg%/*}" - [ ! -f "$z/$x" ] || [ ! -x "$z/$x" ] && [ "$z/$x" = "$arg" ] && - continue - [ "$x" = "$z" ] && [ -x "$z/$x" ] && [ ! -f "$arg" ] && z= - p=":$z:$PATH" - while [ "$p" != "${p#*:}" ]; do - p="${p#*:}" - d="${p%%:*}" - if [ -f "$d/$x" ] && [ -x "$d/$x" ]; then - printf %s\\n "$d/$x" - v=0 - break - fi - done + case "$arg" in + ''|*/ ) + : + ;; + */* ) + if [ -f "$arg" ] && [ -x "$arg" ]; then + printf %s\\n "$arg" + v=0 + fi + ;; + * ) + p=":$PATH" + while [ "$p" != "${p#*:}" ]; do + p="${p#*:}" + d="${p%%:*}/$arg" + if [ -f "$d" ] && [ -x "$d" ]; then + printf %s\\n "$d" + v=0 + break + fi + done + ;; + esac done return $v }