Tcl Variables

Tcl variables are always strings even when they contain numeric values. For most applications, using strings has no effect, but occasionally a HyperWorks application will expect a real number and passing a string will cause an error.

Tcl variables may not contain tabs, spaces, carriage returns, nor the following characters: $ [ ] { } . #

The set command is used to associate variables with data.
set var1 "one plus one equals";
set var2 "2";

set can also return the value of a variable. This can be useful when using one variable to reference the name of another variable.

set var1 "one plus one equals 2"; 
set var1; 
one plus one equals 2 

set var2 "var1"; 
set var2; 
var1 

set [set var2]; 
one plus one equals 2
Placing a $ before a variable name will replace (substitute) the variable with its associated value.
puts "The expression: $var1 $var2";

The expression: one plus one equals 2
To set a variable to nothing:
set var2 "2";
set var2 {};
puts $var2;

Tcl returns a carriage return.

To remove a variable from the current script use the unset command. This is handy because there are commands to check a variables existence.
set var2 "2";
unset var2;
puts $var2;

can't read "var2": no such variable