There are a few various techniques to accomplish that. If your intention is to restore the value of a variable, you might be able to use something like this:
proc savevars {file varlist} {
set fId [open $file "WRONLY CREAT TRUNC"]
foreach var $varlist {
upvar #0 $var tmp
puts $fId [list set $var $tmp]
}
close $fId
}
Then, all you have to do to save is call savevars with the file to store variables in, and the list of variables to save, and load the savefile as a normal script to restore:
You could also save the variables automatically, using something like this.
In this case, you use register_savevar to tell the script which global variables to save.