On 2018-11-4 08:10 , Helmut K. C. Tessarek wrote:
> set reinplace_cmd [subst -nobackslashes -nocommands
> {s/bad/awesome/g}]
> reinplace -E $reinplace_cmd FILE

This example misses the point because the command does not contain any
characters that have a special meaning in Tcl. The only reason you
needed to use subst is because you had a variable you wanted substituted
*and* had other special characters that you didn't want substituted.

This works fine: reinplace -E "s/bad/awesome/g" FILE

So does this: reinplace -E "s/bad/${good}/g" FILE

And this: reinplace -E {s/\[bad\]/good/g} FILE

It's only when you have those literal brackets *and* you want ${good} to
be treated as a Tcl variable that you need a different approach. And you
have exactly this problem running sed from a shell, just with a
different set of characters that need protecting. Single quotes in the
shell are very similar to Tcl's braces, stopping parameters from being
expanded.

Note that you could also go another layer deep into backslash hell to
solve this problem, but I really try to avoid recommending that.

- Josh

Attachment: signature.asc
Description: OpenPGP digital signature

Reply via email to