<pre><code>lifecycle:
  preStop:
    exec:
      command: [&quot;sh&quot;, &quot;-c&quot;, &quot;curl -v  -X PUT -d '\&quot;SHUTTING_DOWN\&quot;'  http://localhost:8080/v1/info/state&quot;]
</code></pre>
<p>I am expecting this will produce a curl url like</p>
<pre><code>curl -v  -X PUT -d '&quot;SHUTTING_DOWN&quot;' http://localhost:8080/v1/info/state 
</code></pre>
<p>How ever I am getting with extra single quotes surrounded ''&quot;SHUTTING_DOWN&quot;''</p>
<pre><code>curl -v  -X PUT -d ''&quot;SHUTTING_DOWN&quot;'' http://localhost:8080/v1/info/state 
</code></pre>
<p>Any pointers, where am I going wrong?</p>

<p>I'd suggest getting rid of as many layers of quotes as you can.  In the original example you have a layer of quotes from YAML, plus a layer of quotes from the <code>sh -c</code> wrapper.  Since you need the HTTP PUT body itself to have both single and double quotes – you need to send the string <code>'&quot;SHUTTING_DOWN&quot;'</code> with both kinds of quotes over the wire – getting rid of as much quoting as you can is helpful.</p>
<p>In both the <a href="https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_02" rel="nofollow noreferrer">shell</a> and <a href="https://yaml.org/spec/1.2.2/#73-flow-scalar-styles" rel="nofollow noreferrer">YAML</a>, the two kinds of quotes behave differently.  Backslash escaping only works in double-quoted strings and so you probably need that at the outer layer; then you need single quotes inside the double quotes; and then you need backslash-escaped double quotes inside that.</p>
<p>In YAML specifically the quotes around strings are usually optional, unless they're required to disambiguate things (forcing <code>'true'</code> or <code>'12345'</code>) to be strings.  This lets you get rid of one layer of quoting.  You also may find this slightly clearer if you use YAML <em>block style</em> with one list item on a line.</p>
<pre class="lang-yaml prettyprint-override"><code>command:
  - /bin/sh
  - -c
  - curl -v -X PUT -d &quot;'\&quot;SHUTTING_DOWN\&quot;'&quot; http://localhost:8080/v1/info/state
</code></pre>
<p>I might even go one step further here, though.  You're not using environment variable expansion, multiple commands, or anything else that requires a shell.  That means you don't need the <code>sh -c</code> wrapper.  If you remove this, then the only layer of quoting you need is YAML quoting; you don't need to worry about embedding a shell-escaped string inside a YAML-quoted string.</p>
<p>You do need to make sure the quotes are handled correctly.  If the string begins with a <code>'</code> or <code>&quot;</code> then YAML will parse it as a quoted string, and if not then <a href="https://yaml.org/spec/1.2.2/#733-plain-style" rel="nofollow noreferrer">there are no escaping options in an unquoted string</a>.  So again you probably need to put the whole thing in a double-quoted string and backslash-escape the double quotes that are part of the value.</p>
<p>Remember that each word needs to go into a separate YAML list item.  <code>curl</code> like many commands will let you combine options and arguments, so you can have <code>-XPUT</code> as a single argument or <code>-X</code> and <code>PUT</code> as two separate arguments, but <code>-X PUT</code> as a single word will include the space as part of that word and confuse things.</p>
<pre class="lang-yaml prettyprint-override"><code>command:
  - curl
  - -v
  - -X
  - PUT
  - -d
  - &quot;'\&quot;SHUTTING_DOWN\&quot;'&quot;
  - http://localhost:8080/v1/info/state
</code></pre>
