On 11/21/2011 01:30 AM, Douglas Garstang wrote:
Grrr. I have the exec{} below in my puppet module. How do I escape the
\ characters? I've tried every possible combination I can think of.
I've used one, I've used two, and I've used THREE \.
exec {
'oracle-extract-part':
command => "/usr/bin/printf
\"n\np\n2\n2091\n+16384M\nw\n\" | /sbin/fdisk /dev/xvdj",
unless => "/bin/cat /proc/partitions | /bin/grep
${orcl_ephm_device}2";
}
Sounds like you need to use FOUR. Say you wanted to use printf to print
a newline. You would run this:
(1) printf \n
But, the backslash has special meaning in bash (or most shells). If you
type that in bash, you have to escape it, one of these ways:
(2) printf \\n
(3) printf '\n'
Puppet runs commands through a shell. So, you will have to apply
escaping appropriate for whatever shell is in use.
But, the command is also in a string. Backslashes have special meaning
in puppet strings. So, we know the command we want to give to bash is:
(4) printf \\n
To put that in a puppet string we need to escape the \:
(5) "printf \\\\n"
If you don't like all the backslashes, you could give single quotes to bash:
(6) "printf '\\n'"
This is example 3, quoted with puppet's rules. You could also use single
quotes in Puppet, but Puppet's single-quote strings still find special
meaning in \, so it doesn't really get you anything, and if you are
using single quotes for bash it's actually worse. You'd need this:
(7) 'printf \'\\n\''
Given (7), puppet will give (8) to bash:
(8) printf '\n'
and bash will give to exec():
(9) printf \n
Make sense?
--
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+unsubscr...@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/puppet-users?hl=en.