chiark / gitweb /
pwhich: A portable (I believe) /bin/sh implementation of 'which'.
authorColin Watson <cjwatson@chiark.greenend.org.uk>
Mon, 23 Sep 2002 13:31:09 +0000 (13:31 +0000)
committerColin Watson <cjwatson@chiark.greenend.org.uk>
Mon, 23 Sep 2002 13:31:09 +0000 (13:31 +0000)
pwhich [new file with mode: 0644]

diff --git a/pwhich b/pwhich
new file mode 100644 (file)
index 0000000..47aa80c
--- /dev/null
+++ b/pwhich
@@ -0,0 +1,17 @@
+#! /bin/sh -e
+
+RET=1
+for PROGRAM in "$@"; do
+ IFS_SAVE="$IFS"
+ IFS=:
+ for ELEMENT in $PATH; do
+  if [ -f "$ELEMENT/$PROGRAM" -a -x "$ELEMENT/$PROGRAM" ]; then
+   echo "$ELEMENT/$PROGRAM"
+   RET=0
+   break
+  fi
+ done
+ IFS="$IFS_SAVE"
+done
+
+exit "$RET"