Substitution without evaluation - format, subst

Table of Contents

Substitution without evaluation - format, subst
Example

Substitution without evaluation - format, subst

The Tcl interpreter does only one substitution pass during command evaluation. Some situations, such as placing the name of a variable in a variable, require two passes through the substitution phase. In this case, the subst command is useful.

Subst performs a substitution pass without performing any execution of commands except those required for the substitution to occur, ie: commands within [] will be executed, and the results placed in the return string.

In the example code:


puts "[subst $$c]\n"

The format command can also be used to force some levels of substitution to occur.

subst ?-nobackslashes? ?-nocommands? ?-novariables? string

Passes string

If any of the -no... arguments are present, then that set of substitutions will not be done.

NOTE: subst does not honor braces or quotes.