<p>I am using kubernetes and trying to call the following command:<br>
<code>kubectl set env deployment/server A=a B=b ...etc</code>
My env variables are located in .env file, and each value can contain spaces, non-escaped chars, comments, empty lines and so on:</p>

<pre><code>## Common variables
NODE_ENV=production


## Server variables
SERVER_PORT=8009
CORS_ORIGIN=https://www.example.io,http://www.example.io,http://localhost:3000
SESSION_SECRET=/qm%7HLw"pk(8@"pja#I9CbN#2Lg[%d&gt;5{CDA_9g|ZvZmuZ$]=';EhA#g+C;1&gt;&amp;

</code></pre>

<p>I am trying to parse the .env file so that I can integrate it in the command:</p>

<pre><code>kubectl set env deployment/server $(do magic with .env file to extract the escaped variables)
</code></pre>

<p>Tried <code>grep -v '^#' .env | xargs</code> but it doesn't work with characters that need escaping or quotes. My bash abilities are not the strongest right now. Any idea how to solve this?</p>

<pre><code>cat .env | grep -v '^#\|^$' | xargs -0 echo | tr '\n' ' '
</code></pre>

<p>This would print everything in one line: <code>NODE_ENV=production SERVER_PORT=8009 CORS_ORIGIN=https://www.example.io,http://www.example.io,http://localhost:3000 SESSION_SECRET=/qm%7HLw"pk(8@"pja#I9CbN#2Lg[%d&gt;5{CDA_9g|ZvZmuZ$]=';EhA#g+C;1&gt;&amp;</code>  </p>

<p>I am not sure if you need to keep the <code>VAR=</code> or if you also would like to get rid of that (pipe into <code>sed</code> or <code>awk</code> in the end then and replace it with whatever you need)</p>
