
Empty strings and 'env' array weirdness
Hello Ronald,
sorry to say, but, except from "info exists ...", everything is
allright!
Microsoft platforms, environments work this way:
inside the command shell:
C:\> set a=a
C:\> set a
a=a
ALLUSERSPROFILE=G:\Dokumente und Einstellungen\All Users
APPDATA=G:\Dokumente und Einstellungen\ml\Anwendungsdaten
AVENGINE=G:\PROGRA~1\CA\SHARED~1\SCANEN~1
C:\> set a=
C:\> set a
ALLUSERSPROFILE=G:\Dokumente und Einstellungen\All Users
APPDATA=G:\Dokumente und Einstellungen\ml\Anwendungsdaten
AVENGINE=G:\PROGRA~1\CA\SHARED~1\SCANEN~1
inside the tcl shell:
% set env(a) "a";
% puts $env(a);
a
% set env(a) "";
% puts $env(a);
can't read "env(a)": no such variable
This is right, if you consider the default behaviour of Microsoft
environment variables.
On Unix, I tried it on AIX, HP-UX, IRIX and Solaris, it works like
expected!
But on UNIX a ...
setenv a ""
... will work!
The bug is more or less, that "info exists" tells, that this env array
element exists. Even if it is non-existent.
I don't know exactly how "set env(name) ?data?" works.
But if "set env(name) data" works directly on "putenv( "name=data" )",
than an environment variable will be deleted on Microsoft platforms,
if "data" is empty.
On the same side the env array element seem to be created with "data",
even if "data" is empty.
"info exists env(name)" will return true.
Asking for the contents of the env array could access dynamicly via
"getenv( name ) the environment and so the empty environment variable
will be non-existent. And the local copy of the environment will be
ignored.
If all accesses on the global env array would be dynamic, than there
has been no need for the local copy, the array hashtable, where "info
exists env(name)" asks for array element existence.
Right?
Best regards,
Martin Lemburg
Quote:
> Folks,
> Here's three lines of TCL code that have me perplexed:
> % set env(whatever) "" # set to an empty string
> % info exists env(whatever) # Does it exist.... Yup
> 1
> % puts $env(whatever) # Or does it?
> can't read "env(whatever)": no such variable
> A 'parray' on env also shows that env(whatever) doesn't exist. If I use
> any other array, the 'puts' echoes a blank line. Or, if the string
> contains one of more spaces, all is OK too.
> Of course 'env' is an array that Tcl handles differently than 'normal'
> arrays. But env's behavior with empty strings is something I find
> somewhat unexpected.
> ( Details: Windows XP, Tcl 8.3.5 )