fork download
  1. set x abc
  2. puts "A simple substitution: $x\n"
  3.  
  4. set y [set x "def"]
  5. puts "Remember that set returns the new value of the variable: X: $x Y: $y\n"
  6.  
  7. set z {[set x "This is a string within quotes within braces"]}
  8. puts "Note the curly braces: $z\n"
  9.  
  10. set a "[set x {This is a string within braces within quotes}]"
  11. puts "See how the set is executed: $a"
  12. puts "\$x is: $x\n"
  13.  
  14. set b "\[set y {This is a string within braces within quotes}]"
  15. # Note the \ escapes the bracket, and must be doubled to be a
  16. # literal character in double quotes
  17. puts "Note the \\ escapes the bracket:\n \$b is: $b"
  18. puts "\$y is: $y"
  19.  
Success #stdin #stdout 0.03s 5272KB
stdin
Standard input is empty
stdout
A simple substitution: abc

Remember that set returns the new value of the variable: X: def Y: def

Note the curly braces: [set x "This is a string within quotes within braces"]

See how the set is executed: This is a string within braces within quotes
$x is: This is a string within braces within quotes

Note the \ escapes the bracket:
 $b is: [set y {This is a string within braces within quotes}]
$y is: def