This is very simple. I don’t want to give you any code but the basic idea.
- iterate all the paths in $PATH environment variable.
- for each path check if the executable you are looking for exists.
- if exist echo the current path.
Here is a project findcom I wrote long ago for windows operating system with .net 2.0 that searches for commands. You might get some idea from the source.