Quotes and braces

The distinction between braces ({ }) and quotes (" ") is significant when the list contains references to variables. When references are enclosed in quotes, they are substituted with values. However, when references are enclosed in braces, they are not substituted with values.

Example

With Braces

With Double Quotes

set b 2     

set b 2

set t { 1 $b 3 }

set t " 1 $b 3 "

set s { [ expr $b + $b ] }

set s " [ expr $b + $b ] "

puts stdout $t

puts stdout $t

puts stdout $s

puts stdout $s

will output

1 $b 3                         vs.           1 2 3

[ expr $b + $b ]                            4

Filenames

In Tcl syntax, filenames should be enclosed in braces { } to avoid backslash substitution and white space separation. Backslashes are used to separate folder names in Windows-based filenames. The problem is that sequences of “\n” or “\t” are interpreted specially. Using the braces disables this special interpretation and specifies that the Tcl interpreter handle the enclosed string literally. Alternatively, double-backslash “\\n” and “\\t” would work as well as forward slash directory separators “/n” and “/t”.For example, to specify a file on your Windows PC at c:\newfiles\thisfile.adb, use one of the following:

{C:\newfiles\thisfile.adb}

C:\\newfiles\\thisfile.adb

"C:\\newfiles\\thisfile.adb"

C:/newfiles/thisfile.adb

"C:/newfiles/thisfile.adb"

If there is white space in the filename path, you must use either the braces or double-quotes. For example:

C:\program data\thisfile.adb

should be referenced in Tcl script as

{C:\program data\thisfile.adb} or "C:\\program data\\thisfile.adb"

If you are using variables, you cannot use braces { } because, by default, the braces turn off all special interpretation, including the dollar sign character. Instead, use either double-backslashes or forward slashes with double quotes. For example:

 "$design_name.adb"