From: Iain Patterson Date: Tue, 31 Aug 2010 09:39:03 +0000 (+0100) Subject: Fixed argument handling in find_working. X-Git-Url: http://git.iain.cx/?a=commitdiff_plain;h=a3f02d8c8b8616d1690b382e1e4035e3c0df0dc1;p=profile.git Fixed argument handling in find_working. find_working wasn't using the arguments passed with -a when checking if an executable it found was really working. Added the -A flag to skip argument checking altogether. --- diff --git a/opt/bin/find_working b/opt/bin/find_working index cbbd82d..cec62fa 100755 --- a/opt/bin/find_working +++ b/opt/bin/find_working @@ -3,6 +3,7 @@ # find_working: Find a version of some tool in the PATH which actually runs. # Usage: find_working [options] # Options: -a Use arguments to test executable files. Default --help. +# -A Don't test arguments to executable files. # -q Don't print path to prog. Just exit 0 if found. # -x Don't try to execute unreadable files. Assume success. # -X Don't try to execute unreadable files. Assume failure. @@ -11,9 +12,10 @@ args="-h -? --help" quiet=0 unreadable= -while getopts ":a:qxX" opt; do +while getopts ":a:AqxX" opt; do case $opt in a) args="$OPTARG";; + A) args="";; q) quiet=1;; x) unreadable=0;; X) unreadable=1;; @@ -25,6 +27,7 @@ prog="$1"; shift if [ -z "$prog" ]; then echo >&2 "Usage: find_working [options] " echo >&2 "Options: -a Use arguments to test executable files. Default --help." + echo >&2 " -A Don't test arguments to executable files." echo >&2 " -q Don't print path to prog. Just exit 0 if found." echo >&2 " -x Don't try to execute unreadable files. Assume success." echo >&2 " -X Don't try to execute unreadable files. Assume failure." @@ -36,7 +39,11 @@ for path in ${PATH//:/ }; do [ -x "$path/$prog" ] || continue if [ -r "$path/$prog" ]; then - ldd "$path/$prog" 2>/dev/null | grep "not found" >/dev/null && continue + if [ -n "$args" ]; then + "$path/$prog" $args 2>&1 | grep " $prog " >/dev/null || continue + else + ldd "$path/$prog" 2>/dev/null | grep "not found" >/dev/null && continue + fi ret="$path/$prog" break elif [ -z "$unreadable" ]; then