You could roll a little loop
(
name='gcc-*'
IFS=:; for p in $PATH # Mind filename globbing
do
[ -d "$p" ] && find "$p" -maxdepth 1 -type f -name "$name"
done
)
which can easily be converted to a function
pfind() (
name="$1"
set -f # noglob
IFS=:; for p in $PATH
do
[ -d "$p" ] && find "$p" -maxdepth 1 -type f -name "$name"
done
)
pfind 'gcc-*'
Conveniently you don't need local in this function because the ( … ) already localises the context.
As a final offering, here's the version without a loop
pfind() ( set -f; IFS=:; find $PATH -mindepth 1 -maxdepth 1 -type f -name "$1" 2>/dev/null )
where you have to discard stderr completely in order to avoid outputting errors for directories in $PATH that don't exist