The subst Command

The subst command is useful when you have a mixture of Tcl commands, Tcl variable references, and plain old data. The subst command looks through the data for square brackets, dollar signs, and backslashes, and it does substitutions on those. It leaves the rest of the data alone:

set a "foo bar"
subst {a=$a date=[exec date]}
=> a=foo bar date=Thu Dec 15 10:13:48 PST 1994
					

The subst command does not honor the quoting effect of curly braces. It does substitutions regardless of braces:

subst {a=$a date={[exec date]}}
=> a=foo bar date={Thu Dec 15 10:15:31 PST 1994}
					

You can use backslashes to prevent variable and command substitution.

subst {a=\$a date=\[exec date]}
=> a=$a date=[exec date]
					

You can use other backslash substitutions ...

Get Practical Programming in Tcl & Tk, Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.