TIP #315: Add pathSeparator to tcl_platform Array

Title:Add pathSeparator to tcl_platform Array
Version:$Revision: 1.5 $
Author:Hai Vu <haivu2004 at gmail dot com>
Created:Friday, 04 April 2008


This TIP proposes a mechanism for determining the platform's path separator. The path separator is currently ":" in Unix and ";" in DOS/Windows.


Under Windows, the PATH environment variable consists of many paths, separated by semicolons (";"). Meanwhile, Unix uses colon to separate the paths (":"). Scripts that need to work on both platforms while parsing platform-specific PATH-like environment variables (PATH is just the most common of these) currently need to contain the mapping from platform-type to separator, but this is not especially flexible and some script authors are also inclined to forget about this particular difference.

Thus, to aid portability, this TIP proposes adding an element to the tcl_platform array, pathSeparator, which describes the path separator for the current platform.

Example Usage

The following example prints each component of the PATH environment on a separate line:

set pathList [split $env(PATH) $tcl_platform(pathSeparator)]
foreach path $pathList {
    puts $pathList


puts [string map [list $tcl_platform(pathSeparator) \n] $env(PATH)]


This document has been placed in the public domain.

Powered by Tcl[Index] [History] [HTML Format] [Source Format] [LaTeX Format] [Text Format] [XML Format] [*roff Format (experimental)] [RTF Format (experimental)]

TIP AutoGenerator - written by Donal K. Fellows