#!/usr/bin/env python # Search for a string in $PATH # Copyright 2003 by Akkana Peck. # You may use, distribute or modify this program under the terms of the GPL. import sys, string, os, types verbose = 0 path = os.environ["PATH"] pathdirs = string.split(path, ":") def getMatchingFiles(pat, files) : matches = [] lc = string.lower(pat) for fil in range(0, len(files)) : #print "Looking for", lc, "in", files[fil] callfile = string.lower(files[fil]) if (string.find(callfile, lc) >= 0) : matches.append(files[fil]) return matches def findPatInPath(pat) : for dir in pathdirs : if verbose : print "===", dir, ":" try : progs = os.listdir(dir) except OSError, e: if verbose : print " not found" continue matches = getMatchingFiles(pat, progs) for prog in matches : if verbose : print " ", print prog # main() start = 1 if sys.argv[start] == "-v" : start = start + 1 verbose = 1 for argp in range(1, len(sys.argv)) : findPatInPath(sys.argv[argp])