<p>I'd like to pass env vars into the <code>exec</code> command.</p>

<p>So far I have tried the following</p>

<pre><code>SOME_VAR="A String"

kubectl exec -it a-pod-name -- sh -c 'env NEW_VAR=$SOME_VAR; echo $NEW_VAR &gt; some-file-name.txt'
</code></pre>

<p>I realise I could use <code>kubectl cp</code> if I wanted to copy files, but that doesn't fit my use case.</p>

<p>You need to put the command in double quotes and it will work like following:</p>

<pre><code>kubectl exec -it a-pod-name -- sh -c "env new_var=$var; echo $new_var &gt; some-file-name.txt"
</code></pre>

<p>The reason behind that is bash doesn't extract variable into values in single quotes and hence you need to use double quotes.</p>
