Skip to content

Instantly share code, notes, and snippets.

@hmml
Created January 15, 2014 09:28
Show Gist options
  • Save hmml/8433271 to your computer and use it in GitHub Desktop.
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.
#!/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