parsing ENV['PATH'] 
Author Message
 parsing ENV['PATH']

What am I doing wrong here?

ENV["PATH"].split(':').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.

Thanks,
P

--

^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^
Peter Ensch,

^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^



Tue, 27 Sep 2005 05:46:45 GMT  
 parsing ENV['PATH']

Quote:

> What am I doing wrong here?

> ENV["PATH"].split(':').each { |i|
>   puts i
>   # do more stuff here
> }

> 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.

It works fine for me. Both with double/single quotes.

How does you initial string looks ?

in the "# do more stuff here" section, are you calling break ?

--
Simon Strandgaard



Tue, 27 Sep 2005 09:34:33 GMT  
 parsing ENV['PATH']



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



Tue, 27 Sep 2005 14:49:05 GMT  
 parsing ENV['PATH']

Quote:


> > What am I doing wrong here?

> > ENV["PATH"].split(':').each { |i|
> >   puts i
> >   # do more stuff here
> > }

> > 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.

> It works fine for me. Both with double/single quotes.

> How does you initial string looks ?

> in the "# do more stuff here" section, are you calling break ?

What I'm trying to do is find the path to a certain program on my
system, like

ENV["PATH"].split(':').each { |path|

FileTest.exist?("#{path}/cleartool")

Quote:
}

The problem is that ENV['PATH'] doesn't contain what I expect. When I
run env in
my c shell, I get a line like this:

PATH=/home/pensch/apps/usr/local/bin:/home/pensch/apps/htmldoc/bin:/home/pensch/bin:/apps/java/j2re1.4.1_01/bin....

so splitting on ':' I feel should get the paths I want. However, running
the script
on Solaris w/ C shell, ENV['PATH'] doesn't contain this string

puts ENV['PATH'] prints '/home/pensch'

The same script on my Linux box (bash) gets the expected result.

I'm stumped. Any ideas?
P

--

***********************************************
Peter Ensch,

***********************************************



Tue, 27 Sep 2005 20:16:09 GMT  
 parsing ENV['PATH']

Quote:

<snip>
> The problem is that ENV['PATH'] doesn't contain what I expect. When I
> run env in
> my c shell, I get a line like this:

> PATH=/home/pensch/apps/usr/local/bin:/home/pensch/apps/htmldoc/bin:/home/pensch/bin:/apps/java/j2re1.4.1_01/bin....

> so splitting on ':' I feel should get the paths I want. However, running
> the script
> on Solaris w/ C shell, ENV['PATH'] doesn't contain this string

> puts ENV['PATH'] prints '/home/pensch'

> The same script on my Linux box (bash) gets the expected result.

> I'm stumped. Any ideas?
> P

As to why your path appears to be incomplete I couldn't tell you.
However, what you're trying to accomplish sounds like the "which"
command.  You can find File.which in the "ptools" package on the RAA, or
on RubyGarden as "FileWhich".

Regards,

Dan



Tue, 27 Sep 2005 22:48:38 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. unshifting a directory onto ENV['PATH']

2. can't read env(DISPLAY) from regexp with $env(DISPLAY)

3. ENV['HOME'] on win32

4. Empty strings and 'env' array weirdness

5. Confused by 'PARSE ARG' or 'PARSE VAR'

6. DLL 'path'

7. 'require' search path

8. 'require' error (ver/path)

9. file = open(path,'wb')?????

10. execfile('bla.py'), can bla.py know its full path

11. sys.path vs os.environ['POST']

 

 
Powered by phpBB® Forum Software