env
Overview
Manipulate environment variables
Syntax
env exists variable
env get variable
env names
env set variable value
env unset variable
Description
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.
Notes
The Tcl env variable was re-implemented as a Tcl command for the following reasons:
- 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
- or:
env get PATH
- The implementation of env as a variable was not thread safe.
- 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.