Updated 2014-08-23 04:48:01 by pooryorick

Finding out tclConfig.sh presents various methods for determining that path of tclConfig.sh in a script.

DGP: Let's put the correct solution first:
package require Tcl 8.5
set d [::tcl::pkgconfig get libdir,install]
puts [file join $d tclConfig.sh]
exit

For the large number of people not yet using Tcl 8.5, continue...

Googie: My first candidate is following code:
foreach d [concat [
    list $tcl_library [lindex $tcl_pkgPath 0]] $auto_path [
        list [file dirname $tcl_library] [
        file dirname [lindex $tcl_pkgPath 0]] [
        file dirname [file dirname $tcl_library]] [
        file dirname [file dirname [lindex $tcl_pkgPath 0]]] [
        file dirname [file dirname [file dirname $tcl_library]]] [
        file dirname [file dirname [
            file dirname [lindex $tcl_pkgPath 0]]]]]] {

    if {[file exists $d/tclConfig.sh]} {
        puts $d/tclConfig.sh
        exit
    }
}

puts none

We can put it into the one Tcl script file and execute from a shell to get info, if we can find tclConfig.sh (returns path pointing to it) or we can't (returns none). I use few levels of file dirname for $tcl_library and $tcl_pkgPath because of some problems on MacOS (tclConfig.sh is places few levels upper than $tcl_library).

BR: What is the significance of the order of directories? And why are you looking into $auto_path and $tcl_pkgPath? The only interesting member of those should be $tcl_library, right? The other entries in $auto_path and $tcl_pkgPath would point to other versions of Tcl at the most, I think, and if there is a tclConfig.sh in those that would counter-productive. So I'd rather do:
proc tclConfigFile {} {
    set d [info library]
    set f $d/tclConfig.sh
    if {[file exists $f]} {return $f}

    set d [file dirname $d]
    set f $d/tclConfig.sh
    if {[file exists $f]} {return $f}

    set d [file dirname $d]
    set f $d/tclConfig.sh
    if {[file exists $f]} {return $f}

    set d [file dirname $d]
    set f $d/tclConfig.sh
    if {[file exists $f]} {return $f}

    error "tclConfig.sh not found"
}