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. puts $x
  10.  
  11. set a "[set x {This is a string within braces within quotes}]"
  12. puts "See how the set is executed: $a"
  13. puts "\$x is: $x\n"
  14.  
  15. set b "\[set y {This is a string within braces within quotes}]"
  16. # Note the \ escapes the bracket, and must be doubled to be a
  17. # literal character in double quotes
  18. puts "Note the \\ escapes the bracket:\n \$b is: $b"
  19. puts "\$y is: $y"
  20.  
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"]

def
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