Node:Double-Quotes, Previous:Delaying Substitution, Up:Syntax (Tcl)


A word can begin with a double-quote and ending with the matching closing double-quote. Substitutions as detailed above are done on the characters between the quotes, and the result is then substituted for the original word. Typically double-quotes are used to group sequences of characters that contain spaces into a single command word.

For example:

set name "Fred the Great"
puts "Hello my name is $name"

outputs Hello my name is Fred the Great. The first command sets the value of variable name to the following double-quoted string "Fred the Great". The the next command prints its argument, a single argument because it is a word delineated by double-quotes, that has had variable substitution performed on it.

Here is the same example but using curly brackets instead of double-quotes:

set name {Fred the Great}
puts {Hello my name is $name}

gives the output Hello my name is $name because substitutions are suppressed by the curly bracket notation.

And again the same example but without either curly brackets or double-quotes:

set name Fred the Great
puts Hello my name is $name

simply fails because both set and puts expect a single argument but without the word grouping effects of double-quotes or curly brackets they find that they have more than one argument and throw an exception.

Being a simple scripting language, Tcl does not have any real idea of data types. The interpreter simply manipulates strings. The Tcl interpreter is not concerned with whether those strings contain representations of numbers or names or lists. It is up to the commands themselves to interpret the strings that are passed to them as arguments in any manner those choose.