code: def which(cmd, path="PATH"):
      
      if os.path.exists(cmd):
          return cmd
      if cmd[0] == '/':
          return None
      for segment in os.getenv(path).split(":"):
          program = os.path.normpath(os.path.join(segment, cmd))
          if os.path.exists(program):
              return program
      return None
docs: Find cmd on PATH.