chiark / gitweb /
pwhich: Cope with zero-length elements in $PATH.
authorColin Watson <cjwatson@chiark.greenend.org.uk>
Fri, 11 Apr 2003 15:09:40 +0000 (15:09 +0000)
committerColin Watson <cjwatson@chiark.greenend.org.uk>
Fri, 11 Apr 2003 15:09:40 +0000 (15:09 +0000)
pwhich

diff --git a/pwhich b/pwhich
index 30d4c67..ebb54c3 100755 (executable)
--- a/pwhich
+++ b/pwhich
@@ -14,7 +14,10 @@ for PROGRAM in "$@"; do
    ;;
   *)
    for ELEMENT in $PATH; do
-    if [ -x "$ELEMENT/$PROGRAM" ]; then
+    if [ -z "$ELEMENT" ]; then
+     ELEMENT=.
+    fi
+    if [ -f "$ELEMENT/$PROGRAM" ] && [ -x "$ELEMENT/$PROGRAM" ]; then
      printf '%s\n' "$ELEMENT/$PROGRAM"
      RET=0
      break