<p>I've connected to a container inside my K8s cluster using:</p>
<pre><code>kubectl -n &lt;namespace&gt; exec -ti &lt;pod&gt; -- bash
</code></pre>
<p>Next I'm looking at the content of files within the <code>/proc</code> virtual folder. So for looking at the environment variables defined for process with id 1, I do <code>cat /proc/1/environ</code>.</p>
<p>The problem is that the output is:</p>
<pre><code>var1=valuevar2=valuevar3=value
</code></pre>
<p>instead of:</p>
<pre><code>var1=value
var2=value
var3=value
</code></pre>
<p>The same thing happens for <code>cat /proc/1/cmdline</code>, as the output is</p>
<pre><code>commandarg1arg2
</code></pre>
<p>instead of</p>
<pre><code>command arg1 arg2
</code></pre>
<p>What's causing the newline and spaces to be omitted from the output, and how can it be corrected?</p>

Mihai Albert
<p>The pieces of the environment can not be separated by Newlines, because a Newline character could be part of the environment string itself. Imagine an environment variable with name X, where its <strong>value</strong> is <code>AB\nY=Z</code>. You could not distinguish it from the case that you have two variables, X and Y.</p>
<p>The heart of the environment managements are the system calls <a href="https://www.proggen.org/doku.php?id=c:lib:stdlib:setenv" rel="nofollow noreferrer"><code>getenv</code> and <code>setenv</code></a>, which are for instance present in the C language. The value of the environment variable is a C-string, i.e. a sequence of bytes terminated by a NUL-byte. In fact, NUL is the only value which is not permitted inside the value of an environment variable.</p>
<p>Hence what your <code>cat</code> shows you is the environment definitions, separated by a NUL-byte.</p>
