Martijn Grendelman
2010-Dec-27 13:13 UTC
[Puppet Users] Unrecognised escape sequence ''\~''
Hi, In one of my modules, I have the following: exec { "/bin/sed -i ''\~^${line}$~d'' ''${file}''": The ''\~'' is there, to make sed use ''~'' as the command separator instead of ''/'', which is too common in the lines I am trying to delete. However, the puppet master now complains: Dec 27 14:07:11 offman01 puppet-master[821]: Unrecognised escape sequence ''\~'' in file /etc/puppet/modules/common/manifests/definitions/line.pp at line 15 Should I worry about that? Best regards, Martijn. -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
On 12/27/2010 02:13 PM, Martijn Grendelman wrote:> Hi, > > In one of my modules, I have the following: > > exec { "/bin/sed -i ''\~^${line}$~d'' ''${file}''": > > The ''\~'' is there, to make sed use ''~'' as the command separator instead of > ''/'', which is too common in the lines I am trying to delete. > > However, the puppet master now complains: > > Dec 27 14:07:11 offman01 puppet-master[821]: Unrecognised escape sequence > ''\~'' in file /etc/puppet/modules/common/manifests/definitions/line.pp at > line 15 > > Should I worry about that?Yes. You probably want sed to see the backslash (so as to keep the shell from expanding ~ to $HOME? I''m not sure exec runs in a full-fledged shell, but I digress). The warning tells you that puppet ignores your attempt at escaping something, so the backslash is silently dropped. Long story short - you need to a) drop the unnecessary escape (optional) or b) escape the backslash itself (critical), depending on what you need to happen. In your case, b. HTH, Felix -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
Martijn Grendelman
2010-Dec-27 13:54 UTC
Re: [Puppet Users] Unrecognised escape sequence ''\~''
Hi,>> In one of my modules, I have the following: >> >> exec { "/bin/sed -i ''\~^${line}$~d'' ''${file}''": >> >> The ''\~'' is there, to make sed use ''~'' as the command separator instead of >> ''/'', which is too common in the lines I am trying to delete. >> >> However, the puppet master now complains: >> >> Dec 27 14:07:11 offman01 puppet-master[821]: Unrecognised escape sequence >> ''\~'' in file /etc/puppet/modules/common/manifests/definitions/line.pp at >> line 15 >> >> Should I worry about that? > > Yes. > > You probably want sed to see the backslash (so as to keep the shell from > expanding ~ to $HOME? I''m not sure exec runs in a full-fledged shell, > but I digress). > > The warning tells you that puppet ignores your attempt at escaping > something, so the backslash is silently dropped. > > Long story short - you need to > a) drop the unnecessary escape (optional) or > b) escape the backslash itself (critical), > depending on what you need to happen. > > In your case, b.Ah well, but the sed line actually works as expected, so my guess is, that Puppet may silently drop the backslash when setting the name/title of the resource, but it does not when it executes the code. If Puppet would drop the backslash, it would surely result in a sed error. If I test it on the command line, I get: /bin/sed: -e expression #1, char 2: unknown command: `^'' Would it make sense to craft a $name for the resource without the escape sequence, and set the command explicitly with ''command => /bin/sed -i ...'' ? Best regards, Martijn. -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
On 12/27/2010 02:54 PM, Martijn Grendelman wrote:> Hi, >>> In one of my modules, I have the following: >>> >>> exec { "/bin/sed -i ''\~^${line}$~d'' ''${file}''": >>> >>> The ''\~'' is there, to make sed use ''~'' as the command separator instead of >>> ''/'', which is too common in the lines I am trying to delete. >>> >>> However, the puppet master now complains: >>> >>> Dec 27 14:07:11 offman01 puppet-master[821]: Unrecognised escape sequence >>> ''\~'' in file /etc/puppet/modules/common/manifests/definitions/line.pp at >>> line 15 >>> >>> Should I worry about that? >> >> Yes. >> >> You probably want sed to see the backslash (so as to keep the shell from >> expanding ~ to $HOME? I''m not sure exec runs in a full-fledged shell, >> but I digress). >> >> The warning tells you that puppet ignores your attempt at escaping >> something, so the backslash is silently dropped. >> >> Long story short - you need to >> a) drop the unnecessary escape (optional) or >> b) escape the backslash itself (critical), >> depending on what you need to happen. >> >> In your case, b. > > Ah well, but the sed line actually works as expected, so my guess is, that > Puppet may silently drop the backslash when setting the name/title of the > resource, but it does not when it executes the code. > > If Puppet would drop the backslash, it would surely result in a sed error. > If I test it on the command line, I get: > > /bin/sed: -e expression #1, char 2: unknown command: `^'' > > Would it make sense to craft a $name for the resource without the escape > sequence, and set the command explicitly with ''command => /bin/sed -i ...'' ?You''re right, I''ve got it backwards. Nothing is silently dropped. Do escape the backslash in order to get rid of that warning message. This will mean trouble *only* if at some point in the future \~ does become a valid escape (and you will lose the backslash to puppet then). Cheers, Felix -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
Martijn Grendelman
2010-Dec-28 10:15 UTC
Re: [Puppet Users] Unrecognised escape sequence ''\~''
On 27-12-10 15:05, Felix Frank wrote:> On 12/27/2010 02:54 PM, Martijn Grendelman wrote: >> Hi, >>>> In one of my modules, I have the following: >>>> >>>> exec { "/bin/sed -i ''\~^${line}$~d'' ''${file}''": >>>> >>>> The ''\~'' is there, to make sed use ''~'' as the command separator instead of >>>> ''/'', which is too common in the lines I am trying to delete. >>>> >>>> However, the puppet master now complains: >>>> >>>> Dec 27 14:07:11 offman01 puppet-master[821]: Unrecognised escape sequence >>>> ''\~'' in file /etc/puppet/modules/common/manifests/definitions/line.pp at >>>> line 15 >>>> >>>> Should I worry about that? >>> >>> Yes. >>> >>> You probably want sed to see the backslash (so as to keep the shell from >>> expanding ~ to $HOME? I''m not sure exec runs in a full-fledged shell, >>> but I digress). >>> >>> The warning tells you that puppet ignores your attempt at escaping >>> something, so the backslash is silently dropped. >>> >>> Long story short - you need to >>> a) drop the unnecessary escape (optional) or >>> b) escape the backslash itself (critical), >>> depending on what you need to happen. >>> >>> In your case, b. >> >> Ah well, but the sed line actually works as expected, so my guess is, that >> Puppet may silently drop the backslash when setting the name/title of the >> resource, but it does not when it executes the code. >> >> If Puppet would drop the backslash, it would surely result in a sed error. >> If I test it on the command line, I get: >> >> /bin/sed: -e expression #1, char 2: unknown command: `^'' >> >> Would it make sense to craft a $name for the resource without the escape >> sequence, and set the command explicitly with ''command => /bin/sed -i ...'' ? > > You''re right, I''ve got it backwards. Nothing is silently dropped. > > Do escape the backslash in order to get rid of that warning message. > This will mean trouble *only* if at some point in the future \~ does > become a valid escape (and you will lose the backslash to puppet then).Crafting a name for the resource without the ''\~'' and putting the command in a ''command =>'' parameter doesn''t make any difference. I have now escaped the backslash and that made the error go away. exec { "/bin/sed -i ''\\~^${line}$~d'' ''${file}''": Thanks, Martijn. -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.