Discussion:
Help: How To Determine Separator in the PATH Environment
(too old to reply)
Hai Vu
2008-03-09 03:06:51 UTC
Permalink
I am trying to write a script that would work on both Windows and Mac
(essentially BSD). I would like to parse the environment variables
into pieces using the the split command. However, in Windows, the
separator is a semicolon (;) and in Unix-based systems, a colon (:).
Currently I am looking at $tcl_platform(platform), if it is "windows",
then use ";"; if it is "unix", then use ":".

Is there a built-in command to return such information? In python, we
have os.path.pathsep for this job.

Hai
Arjen Markus
2008-03-10 08:05:03 UTC
Permalink
Post by Hai Vu
I am trying to write a script that would work on both Windows and Mac
(essentially BSD). I would like to parse the environment variables
into pieces using the the split command. However, in Windows, the
separator is a semicolon (;) and in Unix-based systems, a colon (:).
Currently I am looking at $tcl_platform(platform), if it is "windows",
then use ";"; if it is "unix", then use ":".
Is there a built-in command to return such information? In python, we
have os.path.pathsep for this job.
Hai
Not that I know of, but what you can do is simply add it to
the tcl_platform array when you application starts. Then
whenever you need to split the PATH environment variable
you simply use that value.

But how often does this occur? Why not make a small procedure
that takes care of it?

Ultimately, you might propose to add it to the tcl_platform
array - via a TIP.

Regards,

Arjen
Larry W. Virden
2008-03-10 14:04:02 UTC
Permalink
Post by Hai Vu
Is there a built-in command to return such information? In python, we
have os.path.pathsep for this job.
Did you take a look at the tcl "file" command? For instance, there is

file separator

as well as file split and file join, etc.
Andreas Leitgeb
2008-03-10 15:18:15 UTC
Permalink
Post by Larry W. Virden
Post by Hai Vu
Is there a built-in command to return such information? In python, we
have os.path.pathsep for this job.
Did you take a look at the tcl "file" command? For instance, there is
file separator
as well as file split and file join, etc.
That's not an answer to the original question. It wasn't about
splitting that kind of path, but rather a list of such paths,
as is usually contained in the env-var PATH.
windows: PATH=C:\;C:\windows;...
unix: PATH=/bin:/usr/bin:...

A TIP could be made to add "file pathsep", "file pathsplit" and
"file pathjoin" possibly with some intelligence to avoid multiple
occurrances of literally same single paths.
Larry W. Virden
2008-03-10 15:48:20 UTC
Permalink
That's not an answer to the original question.  It wasn't about
splitting that kind of path, but rather a list of such paths,
as is usually contained in the env-var PATH.
windows:   PATH=C:\;C:\windows;...
unix:      PATH=/bin:/usr/bin:...
A TIP could be made to add "file pathsep", "file pathsplit" and
"file pathjoin" possibly with some intelligence to avoid multiple
occurrances of literally same single paths.
Ah - I misunderstood the original question! Thanks for clarifying. I
agree - a TIP would be the way to address this in the long term.
suchenwi
2008-03-10 15:52:06 UTC
Permalink
Post by Larry W. Virden
That's not an answer to the original question.  It wasn't about
splitting that kind of path, but rather a list of such paths,
as is usually contained in the env-var PATH.
windows:   PATH=C:\;C:\windows;...
unix:      PATH=/bin:/usr/bin:...
A TIP could be made to add "file pathsep", "file pathsplit" and
"file pathjoin" possibly with some intelligence to avoid multiple
occurrances of literally same single paths.
Ah - I misunderstood the original question! Thanks for clarifying. I
agree - a TIP would be the way to address this in the long term.
But just to determine the path separator can be as simple as this
(assuming that [file separator] determines it):

proc file'pathsep {} {expr {[file separator] eq "\\"? ";" : ":"}}
Andreas Leitgeb
2008-03-11 10:38:05 UTC
Permalink
Post by suchenwi
proc file'pathsep {} {expr {[file separator] eq "\\"? ";" : ":"}}
This also makes assumptions, which a portable program had better be free of.

PS: iirc, old macs (pre-X) had the colon as filesep, and afaik
no standard for path lists.
Hai Vu
2008-04-10 04:43:45 UTC
Permalink
A TIP could be made to add "filepathsep", "file pathsplit" and
"file pathjoin" possibly with some intelligence to avoid multiple
occurrances of literally same single paths.
Thank you Andreas, I have submitted a TIP:
http://groups.google.com/group/comp.lang.tcl/browse_thread/thread/c2b1603448aa5f27/184697c7cb364374?lnk=raot
Donald Arseneau
2008-03-11 03:16:11 UTC
Permalink
Post by Hai Vu
I am trying to write a script that would work on both Windows and Mac
(essentially BSD). I would like to parse the environment variables
into pieces using the the split command. However, in Windows, the
separator is a semicolon (;) and in Unix-based systems, a colon (:).
Currently I am looking at $tcl_platform(platform), if it is "windows",
then use ";"; if it is "unix", then use ":".
Are colons or semicolons part of the individual path names on either
system?

Why not

set paths [split $env(PATH) ";:"]

Donald Arseneau ***@triumf.ca
Alexandre Ferrieux
2008-03-11 07:28:48 UTC
Permalink
Post by Donald Arseneau
Post by Hai Vu
I am trying to write a script that would work on both Windows and Mac
(essentially BSD). I would like to parse the environment variables
into pieces using the the split command. However, in Windows, the
separator is a semicolon (;) and in Unix-based systems, a colon (:).
Currently I am looking at $tcl_platform(platform), if it is "windows",
then use ";"; if it is "unix", then use ":".
Are colons or semicolons part of the individual path names on either
system?
Why not
  set paths [split $env(PATH) ";:"]
Surely you've seen "C:\WINDOWS" before...

-Alex
Loading...