#! /bin/sh
# whichall -- find all executables in PATH that match the given name
#
# With the -l flag, this also does a ls -l on them
#
# BUGS: doesn't handle aliases...
#
# AUTHOR: Gary T. Leavens

[ -n "$echo" ] && set -x

USAGE="Usage: $0 [-l] cmd-name ..."

LISTIT='echo'

case "$1" in
    -l)
	LISTIT='ls -l'
	shift
	;;
    -*)
        echo "$USAGE" >&2
	exit 1
	;;
esac

# no arguments?
if test $# -eq 0
then
	echo "$USAGE" >&2
	exit 1
fi

for cmd
do
	for pd in `echo "$PATH" | sed -e 's/^:/. /;s/::/ . /g;s/:/ /g'`
	do
		if test -x "$pd/$cmd"
		then
			$LISTIT "$pd/$cmd"
		fi
	done
done
