http://purl.org/tcl/home/man/tcl8.4/TclCmd/cd.htm ---- A frequently made mistake [FMM] [http://www.phaseit.net/claird/comp.lang.tcl/fmm.html] that programmers make is to attempt to exec the cd command. '''cd''' stands for ''change directory''. This sets a kernel specific piece of information regarding what files within a filesystem the application will see if they use ''relative pathnames'' (that is to say, pathnames either beginning with ./ , ../ , or without any leading directory indicatory). This kernel value is a unique value per process - changing it in one process won't change it in other existing processes. ---- '''Stacking cd''': The following overloaded version keeps a stack of visited directories (implicit "pushd"). The "popd" functionality fires if called as "cd -": if {[info command tcl::cd]==""} {rename cd tcl::cd} proc cd {{dir ""}} { global cd_stack if {$dir=="-"} { set dir [lindex $cd_stack end] set cd_stack [lrange $cd_stack 0 end-1] } else { if {$dir==""} {set dir $::env(HOME)} lappend cd_stack [pwd] } tcl::cd $dir } ;# RS ---- Variant with a little more error checking, an no reliance on env(HOME): if {[llength [info command tcl::cd]] == 0} { rename cd tcl::cd } proc cd {{dir {}}} { variable tcl::cd_lastdir set pwd [pwd] if {$dir eq "-"} { if {![info exists cd_lastdir]} { return } set dir $cd_lastdir } elseif {[llength [info level 0]] == 1} { # no $dir specified - go home set code [catch {tcl::cd } res] } if {![info exists code]} { set code [catch {tcl::cd $dir} res] } if {!$code} { set cd_lastdir $pwd } return -code $code $res }; # JH ---- [Tcl syntax help] - [Arts and crafts of Tcl-Tk programming] - [Category Command]