
Testing and reading env variables on Windows
Tcl 8.2b2 Bug: Generated by Scriptics' bug entry form at
http://www.*-*-*.com/
Responses to this post are encouraged.
------
Submitted by: Ingemar Hansson
OperatingSystem: Windows NT
OperatingSystemVersion: v4.0 SP5
Synopsis: Testing and reading env variables on Windows
ReproducibleScript:
Set an environment variable (at DOS-level):
set tVar=1
# This test will return 0
if {[info exists env(TVAR)]} {
set tv $env(TVAR)
}
# The variable tv will be set !!!
set tv $env(TVAR)
# Now this test will return 1 !!!
if {[info exists env(TVAR)]} {
set tv $env(TVAR)
}
ObservedBehavior:
"info exists" doesn't find env variables that an access the env array
does.
DesiredBehavior:
There seems to be some undocumentet feature when accessing the env
variable. Character case of index to the array doesn't matter (even
though the documentation says it does). I like that (!!!) because that's
the behaviour in the operating system. (Maybe it's an OS API that does
this?).
But the "info exists" command fails until an access with equal character
case is done.
Comments:
This isn't too hard to work around. Instead of the following
construction
if {[info exists env(TVAR)]} {
do something
}
use
if {![catch {set env(TVAR)}]} {
do something
}