<p>I am trying to get the "user" and "pw" variables to resolve in a heredoc that is wrapped with single quotes because it is part of a larger command. I believe that as described here
<a href="https://stackoverflow.com/questions/4937792/using-variables-inside-a-bash-heredoc">Using variables inside a bash heredoc</a>
the issue is due to single quotes around the entire command including the "END" portion, but I am not seeing an alternative to wrapping the entire command in quotes because the heredoc is being passed to the mongo shell as a single argument in kubernetes. The code is as follows:</p>

<pre><code>#!/bin/bash

user="theUser"
pw="thePW"

doc='mongo &lt;&lt;END
use DATABASE
db.auth("$user", "$pw")
db.collection.find()
END
'
value=$(kubectl exec -it mongo-pod -- bash -ec "$doc")

echo $value
</code></pre>

JabberwokyStrollin
<p>Put double quotes around the string in the variable assignment, so that variables will be expanded in it.</p>

<pre><code>doc="mongo &lt;&lt;END
use DATABASE
db.auth('$user', '$pw')
db.collection.find()
END
"
</code></pre>
