tcl Tcl Language Constructs Quoting


Example

In the Tcl language in many cases, no special quoting is needed.

These are valid strings:

abc123
4.56e10
my^variable-for.my%use

The Tcl language splits words on whitespace, so any literals or strings with whitespace should be quoted. There are two ways to quote strings. With braces and with quotation marks.

{hello world}
"hello world"

When quoting with braces, no substitutions are performed. Embedded braces may be escaped with a backslash, but note that the backslash is part of the string.

% puts {\{ \}}
\{ \}
% puts [string length {\{ \}}]
5
% puts {hello [world]}
hello [world]
% set alpha abc123
abc123
% puts {$alpha}
$alpha

When quoting with double quotes, command, backslash and variable substitutions are processed.

% puts "hello [world]"
invalid command name "world"
% proc world {} { return my-world }
% puts "hello [world]"
hello my-world
% puts "hello\tworld"
hello   world
% set alpha abc123
abc123
% puts "$alpha"
abc123
% puts "\{ \}"
{ }