On Wed, 25 May 2016 16:28:36 +0200 Dimitrios Apostolou <[email protected]> wrote:
DA> On Wed, May 25, 2016 at 4:14 PM, Ted Zlatanov <[email protected]> wrote: >> I propose `mystring` to be a new "literal" string format that indicates >> variable expansion should not be done inside, for unusual cases where >> you really do need `$(foo)` in a Makefile etc. DA> That's an interesting approach but involves changing the language, so lets DA> skip it for now. How about escaping the dollar, does it work today? If not, DA> would that be easy to fix? Ultimately the issue is that the evaluation is not deterministic. Backslashes don't work, see the first report below. Only `$(const.dollar)` works, and it only protects one expansion. So if CFEngine decides to expand again, you're busted, see how avoid2 ends up expanding twice in the second report. edit_line promises are expanded, so this can get really tricky. #+begin_src cfengine3 bundle agent main { vars: "avoid" string => "AVOID"; "avoid2" string => "$(const.dollar)(avoid)"; reports: "$(this.bundle): trying to avoid with a backslash \$(avoid)"; "$(this.bundle): trying to avoid $(avoid2) in a second expansion"; "$(this.bundle): trying to avoid with const.dollar $(const.dollar)(avoid)"; "$(this.bundle): trying to avoid the second expansion $(const.dollar)(avoid2)"; } #+end_src Output: #+begin_src text % cf-agent -KI ./test_avoid_expand.cf R: main: trying to avoid with a backslash \AVOID R: main: trying to avoid AVOID in a second expansion R: main: trying to avoid with const.dollar $(avoid) R: main: trying to avoid the second expansion $(avoid2) #+end_src The other approach I can suggest is to use Mustache templates to write a file, but if any variables in the templates are touched by the string evaluator, you risk expansion. Ted -- You received this message because you are subscribed to the Google Groups "dev-cfengine" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/dev-cfengine/87wpmiqjzx.fsf%40lifelogs.com. For more options, visit https://groups.google.com/d/optout.
