#!/bin/sh

#goes through all of path, and indexes those files which are executable
#matches them to a possible regexp on the command line too
#if second param is non-"", then the match is strict

match="$1"

( echo $PATH | sed 's/:/\
/g' | while read i ; do
#	echo "$i"
	ls -d "$i"/* 2>/dev/null | while read j ; do 
#		echo "$j"
		if [ -x "$j" ] ; then
			echo "$j"
		fi
	done
done ) | (if [ "$match" != "" ] ; then
	if [ "$2" != "" ] ; then
		grep "/$match\$"
	else
		grep "$match"
	fi
else
	cat
fi )
