This mimics the shell's path resolution to locate the executable that would execute if typing it as a command.