分类:
2011-03-17 10:42:01
[]类似于shell中的反单引号。不过大括号中的[]不执行替换。如果方括号前面有斜杠则不替换。
实例:
set x abc
puts "A simple substitution: $x\n"
set y [set x "def"]
puts "Remember that set returns the new value of the variable: X: $x Y: $y\n"
set z {[set x "This is a string within quotes within braces"]}
puts "Note the curly braces: $z\n"
set a "[set x {This is a string within braces within quotes}]"
puts "See how the set is executed: $a"
puts "\$x is: $x\n"
set b "\[set y {This is a string within braces within quotes}]"
# Note the \ escapes the bracket, and must be doubled to be a
# literal character in double quotes
puts "Note the \\ escapes the bracket:\n \$b is: $b"
puts "\$y is: $y"
执行结果:
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