Created
October 19, 2012 22:11
-
-
Save abatko/3921011 to your computer and use it in GitHub Desktop.
Ruby script that checks the PATH environment variable, and displays its directories one per line
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/ruby | |
abort 'PATH is not set' if ENV['PATH'].nil? | |
seen = Hash.new | |
output = '' | |
ENV['PATH'].split(':').each do |p| | |
seen[p] = seen[p].nil? ? 1 : seen[p]+1 | |
output += " #{p}" | |
output += ' # does NOT exist' unless File.directory?(p) | |
output += ' # duplicate' if seen[p] > 1 | |
output += ' # current directory (.) in PATH is discouraged' if p == '.' | |
output += "\n" | |
end | |
puts "\n#{output}\n" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment