Quote:
> What am I doing wrong here?
> ENV["PATH"].split(':').each { |i|
> puts i
> # do more stuff here
> }
First of all you should use File::PATH_SEPARATOR to make it more portable
like in
ENV["PATH"].split(File::PATH_SEPARATOR).each { |i|
puts i
# do more stuff here
Quote:
}
Additionally you could eliminate empty paths by doing:
ENV["PATH"].split(File::PATH_SEPARATOR).reject{ |d| d=="" }.each { |i|
puts i
# do more stuff here
Quote:
}
or even
ENV["PATH"].split(Regexp.new(File::PATH_SEPARATOR+"+")).each { |i|
puts i
# do more stuff here
Quote:
}
> My PATH env. variable is a long list of ':' separated
> paths; however ENV['PATH'] only sees the first path.
> So, the 'split' works fine, it's the initial string I'm
> splitting that is the problem.
> I know I'll feel dumb once I know the answer.
To make sure that ENV["PATH"] yields what you expect I'd include a puts
statement at the beginning of the script. If you are working on Win with
cygnus bash then the shell tries to do some smart conversions between Unix
and Windows PATH separator conventions which may lead to surprising
results.
Robert