Forum: Cfengine Help Subject: regexp parameter quoting Author: jonb1987 Link to topic: https://cfengine.com/forum/read.php?3,21851,21851#msg-21851
I have the following snippets for cfengine 3 (3.0.5)... #---------------------------------------------------------- bundle agent main { #---------------------------------------------------------- files: any:: "/etc/passwd" comment => "Set compat mode in passwd", edit_line => fix_line("^+::::::.*", "+::::::/bin/bash"); } #---------------------------------------------------------- bundle edit_line fix_line(pattern, line) { #---------------------------------------------------------- # If pattern does not exist # Add line # elsif line does not match # replace with line # So pattern must be anchored and match whole line #---------------------------------------------------------- vars: # Create a regexp string for line with whitespace replaced by \s+ # NOTE: This doesn't actually work as intended: rlne strings are still left with original literal spaces. Hmm... "rline" string => execresult("/bin/echo -e \"$(line)\c\" | /usr/bin/perl -pe 's/\s+/\\s+/g'", "useshell"); classes: # Check for missing pattern, or incorrect line "missing" not => regline("$(pattern)","$(edit.filename)"); "wrong" not => regline("$(rline)", "$(edit.filename)"), comment => "rline : $(rline)"; insert_lines: missing:: "$(line)"; replace_patterns: wrong.!missing:: "$(pattern)" replace_with => value("$(line)"); reports: missing:: "Added to $(edit.filename) : $(line)"; wrong.!missing:: "Fixed in $(edit.filename) : $(line)"; } But looking in the output I see... * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * cf3 BUNDLE fix_line( {'^+::::::.*','+::::::/bin/bash'} ) cf3 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * cf3 cf3 ? Augment scope fix_line with pattern cf3 ? Augment scope fix_line with line cf3 cf3 = = = = = = = = = = = = = = = = = = = = = = = = = = = = cf3 vars in bundle fix_line cf3 = = = = = = = = = = = = = = = = = = = = = = = = = = = = cf3 cf3 cf3 ......................................................... cf3 Promise handle: cf3 Promise made by: rline cf3 ......................................................... cf3 cf3 cf3 = = = = = = = = = = = = = = = = = = = = = = = = = = = = cf3 classes in bundle fix_line cf3 = = = = = = = = = = = = = = = = = = = = = = = = = = = = cf3 cf3 Regular expression error "nothing to repeat" in expression "^+::::::.*" at 1 cf3 !! Could not parse regular expression '^+::::::.*' So I quoted the '+' and I still get a similar problem... * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * cf3 BUNDLE fix_line( {'^\+::::::.*','+::::::/bin/bash'} ) cf3 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * cf3 cf3 ? Augment scope fix_line with pattern cf3 ? Augment scope fix_line with line cf3 cf3 = = = = = = = = = = = = = = = = = = = = = = = = = = = = cf3 vars in bundle fix_line cf3 = = = = = = = = = = = = = = = = = = = = = = = = = = = = cf3 cf3 cf3 ......................................................... cf3 Promise handle: cf3 Promise made by: rline cf3 ......................................................... cf3 cf3 cf3 = = = = = = = = = = = = = = = = = = = = = = = = = = = = cf3 classes in bundle fix_line cf3 = = = = = = = = = = = = = = = = = = = = = = = = = = = = cf3 cf3 cf3 ......................................................... cf3 Promise handle: cf3 Promise made by: missing cf3 ......................................................... cf3 cf3 Regular expression error "nothing to repeat" in expression "+::::::/bin/bash" at 0 cf3 !! Could not parse regular expression '+::::::/bin/bash' cf3 Is there a way to quote the initial '+' that will work (I also tried [+] by the way - still fails!) Any ideas? Thanks! Jon B _______________________________________________ Help-cfengine mailing list Help-cfengine@cfengine.org https://cfengine.org/mailman/listinfo/help-cfengine