Dronacharya
Dronacharya

Reputation: 481

How to access environment variables in an ITCL class?

I know that in a normal tcl script environment variables can be accessed like this:

global env
puts "User: $env(USER)"

set env(IOFILE) "somefile.txt"

but this doesn't seem to work within an ITCL class method. How can I get and set environment variables inside ITCL class code?

Upvotes: 1

Views: 222

Answers (1)

Donal Fellows
Donal Fellows

Reputation: 137767

Itcl does complex things with variable discovery, but you can override the trickiness by giving the fully-qualified name of the variable (the global command will bind the last component of the name in the local scope to the named variable). Thus:

global ::env  ;# <<<<<< Note this <<<<<<

puts "User: $env(USER)"
set env(FOO) "bar"

Upvotes: 3

Related Questions