strange variable of variable evaluation in filesystem path (Windows only)
Closed / Duplicatec8d1585aa9ad549169b42c0fe36e5fbb7746db31Created 13 years agoUpdated 13 years ago
Descriptionplain2013-07-26 13:30:03
Hi,
I have such file/directory structure:
-test (directory)
-a.tcl (file)
-b.tcl (file)
Files content:
#b.tcl
puts "Hello!"
#
#a.tcl
set a test
set b {$a}
source "$b/../b.tcl" ;#this one works on Windows, but doesn't on Linux
source "$b/b.tcl" ;#this one doesn't work on both platforms
#
I run a.tcl and get behaviour as described above. This is not connected with 'source' command only, I noticed that at least 'file normalize' behaves similarly, I mean evaluating $b into pure value of $a.
Best regards,
Bogdan
dgpplain2013-07-26 15:24:25
This report seriously obfuscates matters, but the key issue is a Duplicate of Tcl Bug 969646 [961646ffff]. The handling of paths $noSuchDir/../foo is not platform independent, and is not consistent before and after a [file normalize] is applied. It is not likely this will be fixed. Avoid /../ in your paths when you can, especially for script you plan to port to multiple platforms.
anonymousplain2013-07-29 09:38:59
@dgp: With all respect, how is this a duplicate of ticket 961646ffff? There is no problem with finding file. There is problem with treating something syntaxicaly similar to tcl variable inside such path as real tcl variable. Could you give any details which justify such behaviour in this case? Names with $ are not forbidden on Windows, so let's say I have path "c:/$test" and by accident I have variable 'test' too. In case 961646ffff 'file normalize' helps to prepare acceptable path, but in this case there is no way to do this.
jan.nijtmansplain2013-07-29 10:00:29
> source "$b/../b.tcl" ;#this one works on Windows, but doesn't on Linux
That this works on Windows is actually a Windows bug, it shouldn't
work at all!
@bogdan, So, you are making two mistakes: 1) Assume that "set b {$a}" replaces $a with it's content, that's what's making this Bug-report tricky to understand.
2) Handling of paths containing "/../" in "file normalize". That's a dup of [961646ffff] (actually "file normalize" making the same mistake as path resolving on Windows).
So, I concur with dgp on this. Sorry ;-)
anonymousplain2013-07-29 13:00:55
@jan.nijtmans: No need to sorry, obviously I missed something here.
>> source "$b/../b.tcl" ;#this one works on Windows, but doesn't on Linux
> That this works on Windows is actually a Windows bug, it shouldn't work at all!
I suppose that on Windows such path "dir/.." is equal to ".", so "$b/../b.tcl" means "./b.tcl", which is OK in this case.
> So, you are making two mistakes: 1) Assume that "set b {$a}" replaces $a with it's content
I assumed that 'source "$b/../b.tcl"' replaces $b into string '$a', and then, somwhere inside 'source', '$a' into value of variable $a. However, it seems that in case of "dir/.." the 'dir' is just ignored (Windows only? seems like kind of optimization) and such path changed into ".", which makes it working on Windows.
Well, finally I can concur with dgp on this too. Thanks!
Log in (anonymous is fine) to add a comment.