<p>I would like to output all namespaces in a single line to a variable so I can delete the namespaces later.</p>
<p>Example:</p>
<pre class="lang-bash prettyprint-override"><code>TOBEDELETED=$(kubectl get namespace -o=name | grep &quot;SOME_NAME&quot;)

eval $(kubectl delete namespace ${TOBEDELETED})
</code></pre>

FattyK
<p>An easy way is to pipe the output of your <code>grep</code> to <code>tr &quot;\n&quot; &quot; &quot;</code> to replace all newlines with spaces. Also, your <code>eval</code> is unnecessary.</p>
<pre><code>TOBEDELETED=$(kubectl get namespace -o=name | grep &quot;SOME_NAME&quot; | tr &quot;\n&quot; &quot; &quot;)
kubectl delete namespace ${TOBEDELETED}
</code></pre>
