RSS
 

which.py

#!/usr/bin/env python
'''
Simplistic Python implementation of the unix `which` command.
'''

import os
import sys

def which(name):
    path_env = os.getenv('PATH')
    for path_itr in path_env.split(':'):
        full_path = "%s/%s" % ( path_itr, name )
        if os.path.exists( full_path ):
            return full_path
    return None

if __name__ == '__main__':
    for name in sys.argv[1:]:
        path = which( name )
        print path
Share

Leave a Reply