
#!/bin/sh
#
# which
#
# based on which by Lawrence S Reznick (Copyright 1990) as printed in
# SysAdmin magazine.
# revised by Christopher J. Calabrese (cjc@ulysses.att.com)

if [ $# = 0 ]
then    echo "usage:\t$0 program [program] ..."
        exit 1
fi

dirs=`echo $PATH | sed '
        s/^:/\.:/
        s/:$/:\./
        s/::/:\;:/'`

unset notfound

while [ $# != 0 ]
do      unset found
        
        oIFS="$IFS"
        IFS=":"
        for dir in $dirs
        do      if [ -x "$dir/$1" -a ! -d "$dir/$1" ]
                then    echo "$dir/$1"
                        found=true
                        break
                fi
        done

        if [ -z "$found" ]
        then    notfound="$notfound $1"
        fi

        shift
done

if [ -n "$notfound" ]
then    echo "No $notfound in " `echo $dirs | sed 's/:/ /g'`
fi

