NAME

subst - Perform backslash, command, and variable substitutions

SYNOPSIS

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

DESCRIPTION

This command performs variable substitutions, command substitutions, and backslash substitutions on its string argument and returns the fully-substituted result. The substitutions are performed in exactly the same way as for Tcl commands. As a result, the string argument is actually substituted twice, once by the Tcl parser in the usual fashion for Tcl commands, and again by the subst command.

If any of the -nobackslashes, -nocommands, or -novariables are specified, then the corresponding substitutions are not performed. For example, if -nocommands is specified, no command substitution is performed: open and close brackets are treated as ordinary characters with no special interpretation.

If a break exception occurs during the evaluation of a command substitution, the result of the substitution will be the string (as substituted) up to the start of the command substitution. If a continue exception occurs during the evaluation of a command substitution, an empty string will be substituted for that entire command substitution (as long as it is well-formed Tcl.)

EXAMPLES

When it performs its substitutions, subst does not give any special treatment to double quotes or curly braces (except within command substitutions) so the script
set a 44
subst {xyz {$a}}
returns ``xyz {44}'', not ``xyz {$a}'' and the script
set a "p\} q \{r"
subst {xyz {$a}}
return ``xyz {p} q {r}'', not ``xyz {p\} q \{r}''.

The continue and break exceptions allow command substitutions to prevent substitution of the rest of the command substitution and the rest of string respectively, giving script authors more options when processing text using subst. For example, the script

subst {abc,[break],def}
returns ``abc,'', not ``abc,,def'' and the script
subst {abc,[continue;expr 1+2],def}
returns ``abc,,def'', not ``abc,3,def''.

SEE ALSO

Tcl, eval, break, continue

KEYWORDS

backslash substitution, command substitution, variable substitution
Copyright © 1994 The Regents of the University of California.
Copyright © 1994-1996 Sun Microsystems, Inc.
Copyright © 2001 Donal K. Fellows
Copyright © 1995-1997 Roger E. Critchlow Jr.