Environment Variables
The global array env
is pre-initialized so that each element corresponds to an environment variable. For example, the path is a list of directories to search for executable programs. From the shell, the path is stored in the variable PATH
. When using Tcl, the path is contained in env(PATH)
. It is manipulated just like any other variable.
tclsh>set env(PATH)
/usr/local/bin:/usr/bin:/bin tclsh>set env(PATH) ".:$env(PATH)" ;# prepend current dir
.:/usr/local/bin:/usr/bin:/bin
Modifications to the env
array do not affect the parent environment, but new processes that are created (using exec
, for instance) will inherit the current values (including any new elements that have created).
Get Exploring Expect now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.