[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: quoting and parentheses in ExecResult?
From: |
Knut Auvor Grythe |
Subject: |
Re: quoting and parentheses in ExecResult? |
Date: |
Mon, 15 Aug 2005 10:22:12 +0200 |
User-agent: |
Mutt/1.5.6i |
On Mon, Aug 15, 2005 at 01:12:44PM +1200, Steve Wray wrote:
>> someresult = ( ExecResult("/bin/sh -c '/bin/echo baz|/bin/sed -e
>> \"s/^\(.*\)$/&.conf/g\"'"
Of course, I forgot closing my parentheses at the end here. I hope you
saw.
>> That way cfengine should read this as a single string all the way to the
>> next unescaped double quote (and naturally unescape the quotes inside
>> when running the command).
>
> Interestingly, this does seem to generate a parse error:
>
> cf:cfengine::./testing.cf:24: ExecResult(/command) must specify an
> absolute path
> cfengine::./testing.cf:24: Warning: Redefinition of macro
> someresult=$/&.conf/g\"'" (or perhaps missing quote)
> cf:cfengine::./testing.cf:26: syntax error
>
> I've come across this before; it almost looks as if cfengine is
> assigning a value to $(someresult) twice.
Yes, I believe it does that when it finds whitespace in the middle of
the argument. Like foo = ( bar baz ) is first set to bar, and then baz.
It is probably a side-effect of some sort of list-iteration gizmo.
>> Older versions of cfengine seem to not like quoting of the entire
>> string, but this seems to be fixed in newer versions. Upgrading might be
>> worth a shot if you're still on an older version.
>
> I'm seeing this on the version I d/l'd and compiled on Saturday... 2.1.15
Oh, okay. Then it's probably only fixed in classes, and not in groups. I
have the impression that the parsers in each section ar separated from
each other.
Maybe you can try the magic (and horrific) quotes only-syntax? Just be
sure to write a comment about what it does. I believe the syntax is
something like this:
someresult = ( "exec /bin/sh -c '/bin/echo baz|/bin/sed -e
\"s/^\(.*\)$/&.conf/g\"'" )
If I remember correctly, "exec /" in the beginning of the string makes
it get evaluated instead of just copied. And yes, the '/' is important.
I find this syntax quite horrible, since it differs so much from the
rest of cfengine, so you should probably sheck out Marks new patch
before even considering it.
> the -c yes, but I'm not sure what you mean by 'unecessary parentheses'.
> They are required for the '&' reference to work.
No, they are required for \1 to work. '&' is always the entire match.
Like this:
echo foo | sed 's/\(.*\)/\1.conf/'
...or like this:
echo foo | sed 's/.*/&.conf/'
Both methods give the same result. using parentheses and \1 is often
favored, because some languages (like Perl) do all regexes in the script
a lot slower if $& is used at all (not just the regex associated with
the usage, it enables a global option turning things slooow).
The ^ and $ are also unnecessary in this case, since regex is greedy.
If you are able to write your pattern match differently, maybe you can
work around the problem this time?
--
Knut Auvor Grythe
ITEA Systemdrift
Re: quoting and parentheses in ExecResult?, Adrian Phillips, 2005/08/15
Re: quoting and parentheses in ExecResult?, Mark Burgess, 2005/08/15