in reply to file test results not as expected

Using Path::Tiny

$ perl -MPath::Tiny -E 'for my $dir ( split(/:/,$ENV{PATH}) ){say for +grep {-f -x $_} path($dir)->children }'

Also depending on your shell it may already have these cached. For instance ZSH provides a commands hash which maps from the command name to the corresponding file name.

$ print -l "${(@k)commands}" | sort | tail zipinfo zipnote zipsplit zless zmore zmqshell.py znew zprint zsh zsh-5.8 $ print $commands[zsh] /usr/local/bin/zsh

Edit: Dump the ZSH cache with for i in "${(@onk)commands}" ; { printf "%20s\t%s\n" "$i" "$commands[$i]" } | less; of course keep in mind that the commands parameter shows only what would be found first on PATH; if you're looking for exhaustive (including things with matching names shadowed in subsequent directories) you'd want the other solutions.

The cake is a lie.
The cake is a lie.
The cake is a lie.