chiark / gitweb /
s/adare/royal/
[bin.git] / pwhich
1 #! /bin/sh
2 set -e
3
4 RET=1
5 for PROGRAM in "$@"; do
6  IFS_SAVE="$IFS"
7  IFS=:
8  case $PROGRAM in
9   */*)
10    if [ -x "$PROGRAM" ]; then
11     printf '%s\n' "$PROGRAM"
12     RET=0
13    fi
14    ;;
15   *)
16    for ELEMENT in $PATH; do
17     if [ -z "$ELEMENT" ]; then
18      ELEMENT=.
19     fi
20     if [ -f "$ELEMENT/$PROGRAM" ] && [ -x "$ELEMENT/$PROGRAM" ]; then
21      printf '%s\n' "$ELEMENT/$PROGRAM"
22      RET=0
23      break
24     fi
25    done
26    ;;
27  esac
28  IFS="$IFS_SAVE"
29 done
30
31 exit "$RET"