TCL的执行分为两步,第一步替换,第二步执行。。
在方括号[]中的内容将在替换步骤中计算出结果,整体替换为结果,类似于C中调用函数。方括号在反斜杠后或在花括号内无此作用。例子:
set b "\[set y {This is a string within braces within quotes}]" ;#y值有更新
puts $b
输出。。[set y {This is a string within braces within quotes}]
set z {[set x {This is a string within quotes within braces}]} ;#x值有更新
puts $z
输出。。[set x {This is a string within quotes within braces}]
在双引号和花括号中的内容将视为一个参数
在双引号中的内容在替换步骤中,执行替换。。例如, puts "The current stock value is $varName" 中的varName将会被替换为varName的值。
大多在反斜杠后的内容表示不被替换。。如 \",但有一些反斜杠后的内容表示要被替换,如下表中内容。。但是如果一个反斜杠在行尾,表示下一行的内容和这行的内容是同一行,tcl将会用一个空格替换行尾的反斜杠。。
String | Output | Hex Value |
---|---|---|
\a | Audible Bell | 0x07 |
\b | Backspace | 0x08 |
\f | Form Feed (clear screen) | 0x0c |
\n | New Line | 0x0a |
\r | Carriage Return | 0x0d |
\t | Tab | 0x09 |
\v | Vertical Tab | 0x0b |
\0dd | Octal Value | d is a digit from 0-7 |
\uHHHH | H is a hex digit 0-9,A-F,a-f. This represents a 16-bit Unicode character. | |
\xHH.... | Hex Value | H is a hex digit 0-9,A-F,a-f. Note that the \x substitution "keeps going" as long as it has hex digits, and only uses the last two, meaning that \xaa and \xaaaa are equal, and that \xaaAnd anyway will "eat" the A of "And". Using the \u notation is probably a better idea. |
双引号和花括号的这种用法只有当它们用来组织一个参数时才有作用。。例子:
set Z Albany set Z_LABEL "The Capitol of New York is: "
puts "$Z_LABEL {$Z}" puts {Who said, "What this country needs is a good $0.05 cigar!"?}第一行输出。。The Capitol of New York is: {Albany}。。(引号已经起了组织一个参数的作用,故花括号不再起这种作用,作为普通字符)
第二行输出。。Who said, "What this country needs is a good $0.05 cigar!"?
参考链接:https://www.tcl.tk/man/tcl8.5/tutorial/tcltutorial.html