[SPAM] Re: need help with reinplace

Joshua Root jmr at macports.org
Sun Nov 4 01:48:41 UTC 2018


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

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 228 bytes
Desc: OpenPGP digital signature
URL: <http://lists.macports.org/pipermail/macports-dev/attachments/20181104/29c97169/attachment.sig>


More information about the macports-dev mailing list