Tcl provides a convenient way to access the environment variables in a read-only mode through the Tcl global variable env. The variable env is a Tcl array that is automatically created and initialized at startup inside the Tcl interpreter.
Note: After initialization, any change to the
env variable is not applied to the environment outside of the Tcl interpreter. Similarly, any change to your environment variables done after starting the Tcl interpreter will not be reflected by the env variable.The keys of the env array are the environment
variables at the time Vivado Design Suite starts. The keys are case
sensitive.
For example:
Vivado% puts "The PATH variable is $env(PATH) "
To get the list of all the Unix environment variables:
Vivado%: set all_env_var [array names env]
It is possible to check if an environment variable exists (i.e a key to env array exists) by using the info command. For example to check for MYVARNAME:
Vivado% if {[info exists env(MYVARNAME)]} {
}
The env array is a global variable and can therefore be referenced inside a proc after being declared as global.
For example:
proc print_env {} {
global env
puts " UNIX Environment:"
foreach var [lsort [array names env]] {
puts " $var : $env($var)"
}
}