<p>I am using K8S</p>
<p>I want to calculate a string that that is a result of <code>kubectl exec -it ... -c </code></p>
<p>after the <code>-c</code> option there is a string.</p>
<p>How can I pass a string with double quotes inside.</p>
<p>The following example doesn't work properly.</p>
<pre><code>x=&quot;$(kubectl exec -it mysql-pod -- /bin/sh -c \&quot;mysql -uroot -p12345
   -e 'show databases'\&quot; 2&gt;/dev/null)&quot;
echo $x
</code></pre>
<p>Thanks.</p>

<ul>
<li>when only a command needs to be executed on a pod , <code>-it</code> option is not required as it stands for attaching an interactive teminal</li>
<li>when mysql is itself an executable command , no need to use <code>/bin/sh -c</code></li>
<li>no need to encapsulate whole command in <code>&quot; &quot;</code></li>
</ul>
<p>So try following</p>
<pre><code>x=$(kubectl exec mysql-pod -- mysql -uroot -p12345 -e 'show databases ;' 2&gt;/dev/null)
echo $x 
</code></pre>
