Version 9 of pwd

Updated 2004-04-08 05:03:57

pwd - Return the current working directory

http://www.purl.org/tcl/home/man/tcl8.4/TclCmd/pwd.htm


pwd is always a fully normalized path (at least in Tcl 8.4a4 or newer). This differs from Tcl 8.3 or older, where (on some platforms at least) pwd was whatever non-unique file representation was last passed to cd. In Tcl8.4 pwd is guaranteed to be the unique normalized string representation of the path.

pwd may actually lie inside a virtual filesystem (and therefore be different to the OS'es perception of the pwd), if any are mounted.

pwd can actually change under some circumstances without the use of cd, for example if pwd is inside a directory which is deleted with file delete -force, Tcl moves the pwd out of the directory before deleting.

Note that the current directory is unfortunately a process-resource - so if you're using multiple interps in an event-driven situation, relying on a particular working directory between calls may cause you grief. In fact even without multiple interps you shouldn't write procs that rely on a particular working directory as again, you could get unexpected results if calls are interleaved with other parts of your application.


Under what circumstances might [pwd] fail to return a result? I would have assumed it would be guaranteed to return a path without error - but the result below shows otherwise. (on FreeBSD 4.9-STABLE tcl8.4.4 tclkit)

 error getting working directory name: no such file or directory
     while executing
 "pwd"
     (in namespace eval "::math" script line 20)
     invoked from within
 "namespace eval ::math { 

     variable version 1.2.2

     # misc.tcl

     namespace export    cov             fibonacci       integrate
     namespace export    max             mean            min..."
     (file "/root/shelltests/nefualert.vfs/lib/tcllib1.5/math/math.tcl" line 15)
     invoked from within
 "source /root/shelltests/nefualert.vfs/lib/tcllib1.5/math/math.tcl"
     ("package ifneeded" script)
     invoked from within
 "package require math"



Tcl syntax help - Arts and Crafts of Tcl-Tk Programming - Category Command - Category Introspection