Created
January 15, 2014 09:28
-
-
Save hmml/8433271 to your computer and use it in GitHub Desktop.
Inspect $PATH environment variable for duplicates and invalid paths. Prints cleaned version afterwards.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import os | |
paths = os.getenv('PATH').split(os.pathsep) | |
cleaned_paths = [] | |
for path in paths: | |
if path in cleaned_paths: | |
print 'Duplicated:', path | |
continue | |
if not os.path.exists(path): | |
print 'Doesn\'t exist: ', path | |
continue | |
cleaned_paths.append(path) | |
print 'Cleaned PATH:', os.pathsep.join(cleaned_paths) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment