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