#! /bin/sh
:
#
#       which - check the PATH for a command
#

# the original which(1) doesn't complain about missing arguments...
#
if [ $# -eq 0 ] ; then
        echo "Usage: `basename $0` command ..." >&2
        exit 2
fi

notfound=""
oIFS="$IFS"
IFS=":"

# re-express $PATH with its true meaning
#
dirs=`echo "$PATH" | sed -e 's/^:/.:/' -e 's/:$/:./' -e 's/::/:.:/g'`

while [ $# -ne 0 ] ; do
        found=false
        for dir in $dirs ; do
                if [ -x "$dir/$1" -a ! -d "$dir/$1" ] ; then
                        echo "$dir/$1"
                        found=true
                fi
        done
        if $found ; then
                :
        else
                notfound="$notfound $1"
        fi
        shift
done
if [ -n "$notfound" ] ; then
        echo "no$notfound in `echo $dirs | sed 's/:/ /g'`"
fi
exit 0

