#!/bin/sh
# which: where is the command I am executing? (based on script from K & P)
#	but prints all the programs that could be what you really wanted.
#	try ``which *ail'' to get all the mail programs...

opath=$PATH
files=
opts=
PATH=/bin:/usr/bin

for arg
do
	case "$arg" in
	-*)	opts="$opts $arg";;	# ls options
	*)	files="$files $arg";;
	esac
done

case $files in
"")	echo "usage: $0 command" 1>&2; exit 1 ;;
esac

for j in $files
do
	foundyet=false
	for i in `echo $opath | sed 's/^:/.:/
				s/::/:.:/
				s/:$/:./
				s/:/ /g' `
	do
#		if test -x $i/$j; then	# ultrix test is busted; no -x
		if test -r $i/$j; then
			ls -d $opts $i/$j
			foundyet=true
		fi
	done

	case $foundyet in
	false) echo "$j: not found" ;;
	esac
done
