Subject: DC-WG: Tcl "source" behavior
From: Robert A. Dilly (dilly@btv.ibm.com)
Date: Tue Mar 07 2000 - 14:42:18 PST
This was discussed in today's meeting, but I thought
I'd log the details here should the question arise
again later....
Bob
Tclsh "source" Experiment
==================================================
While reviewing the DCDL include command, we questioned
what Tcl does for resolving relative path names when
used with the source command. This was a simple
experiment run with Tcl V 8.0 to check.
There are two directories here with two files each.
A "main", run.tcl and a "sourced" file inc.tcl. The
main is identical, but the inc.tcl file has the path
hardcoded so we can tell which got imbedded.
$ find . -ls
24590 4 drwx------ 3 dilly 3876 512 Mar 7 11:51 .
24591 4 -rwxr-xr-x 1 dilly 3876 114 Mar 7 12:15 ./inc.tcl
24592 4 -rwxr-xr-x 1 dilly 3876 94 Mar 7 12:14 ./run.tcl
32768 4 drwx------ 2 dilly 3876 512 Mar 7 11:54 ./subdir
32769 4 -rwxr-xr-x 1 dilly 3876 121 Mar 7 12:15 ./subdir/inc.tcl
32770 4 -rwxr-xr-x 1 dilly 3876 94 Mar 7 12:14 ./subdir/run.tcl
Here are examples of the two files.
$ cat run.tcl
#!/usr/prod/contrib/bin/tclsh
puts "Source for run.tcl: \"[info script]\""
source "inc.tcl"
$ cat inc.tcl
puts "Actual file imbedded \"/tmp/dcdl/inc.tcl\""
puts "\[info script\] reports inc.tcl: \"[info script]\""
There are four cases that can be tried. They all
seem to show that the imbedded file comes from the
current working directory, as opposed to the directory
where the "main" resides. Two of four cases follow:
$ run.tcl
Source for run.tcl: "run.tcl"
Actual file imbedded "/tmp/dcdl/inc.tcl"
[info script] reports inc.tcl: "inc.tcl"
$ subdir/run.tcl
Source for run.tcl: "subdir/run.tcl"
Actual file imbedded "/tmp/dcdl/inc.tcl"
[info script] reports inc.tcl: "inc.tcl"
-- -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- IBM Microelectronics Division ASIC Synthesis and Timing Team -------------------------------- -------------------------------- Bob Dilly 802-769-7786 dilly@us.ibm.com IBM - Dept G46V - MS 863K Essex Junction, VT 05452-4299 tie 446-7786 / dilly@us
This archive was generated by hypermail 2b28 : Tue Mar 07 2000 - 14:45:18 PST