# find_working: Find a version of some tool in the PATH which actually runs.
# Usage: find_working [options] <prog>
# Options: -a <args> Use arguments to test executable files. Default --help.
# find_working: Find a version of some tool in the PATH which actually runs.
# Usage: find_working [options] <prog>
# Options: -a <args> Use arguments to test executable files. Default --help.
# -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.
# -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.
if [ -z "$prog" ]; then
echo >&2 "Usage: find_working [options] <prog>"
echo >&2 "Options: -a <args> Use arguments to test executable files. Default --help."
if [ -z "$prog" ]; then
echo >&2 "Usage: find_working [options] <prog>"
echo >&2 "Options: -a <args> Use arguments to test executable files. Default --help."
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."
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."
- 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