TIP 315: Add pathSeparator to tcl_platform Array

Author:		Hai Vu <[email protected]>
State:		Final
Type:		Project
Tcl-Version:	8.6
Vote:		Done
Created:	04-Apr-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.