Skip to content

Instantly share code, notes, and snippets.

@abatko
Created October 19, 2012 22:11
Show Gist options
  • Save abatko/3921011 to your computer and use it in GitHub Desktop.
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
#!/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