[ Previous ] [ Contents ] [ Index ] [ Next ]



Manipulate environment variables


env exists variable

env get variable

env names

env set variable value

env unset variable


env exists returns 1 if the variable is set and 0 if it is not set.

env get returns the value of the specified environment variable.

env names returns a list of the names of all environment variables. (Only the names are returned, not the values.)

env set sets the specified environment variable to the specified value.

env unset unsets the specified environment variable.


The Tcl env variable was re-implemented as a Tcl command for the following reasons:

  1. Environment variables are not case-sensitive on certain platforms. The env variable code always copied the variables and preserved case into a Tcl array so you may think $env(PATH) wasn't set when in fact $env(Path) was set. This could cause problems when, for example, preparing for an exec. The env command does the right thing and returns the same value with:

           env get Path


           env get PATH

  2. The implementation of env as a variable was not thread safe.

  3. The implementation of env as a command always fetches, in a thread safe way, the actual environment variables. In the implementation of env as a variable, on the other hand, the environment variables are copied to the env global array at Tcl interp startup. Therefore, if C code changes the environment, with putenv("foo=bar") for example, the env array wouldn't see the change.

Top of Page

[ Previous ] [ Contents ] [ Index ] [ Next ]
Copyright © 1998-99 America Online, Inc.