<p>In my pod I have some env variables. I have written a bash script to get inside the pod and connect to database using the env variables. But am not able to use the env variables.</p>
<pre class="lang-sh prettyprint-override"><code>kubectl exec $POD_ID  -- /bin/bash -c &quot;&quot;&quot;
     printenv DATABASE_HOST_NAME
     echo $DATABASE_HOST_NAME
     psql -h $DATABASE_HOST_NAME -U DATABASE_USER
&quot;&quot;&quot;
</code></pre>
<p>Here printenv returns the correct env variable value. echo returns empty. And psql statement doesn't take the host.
Anyone has any idea how i can use the env variables in the pod in my psql connection statement.</p>
<p>When i manually get in the container and run the psql command with env variable it works file.But when running the script it shows the error.</p>

Origin
<p>As <code>DATABASE_HOST_NAME</code> is defined in k8s pod, you need single quote to avoid <code>$DATABASE_HOST_NAME</code> to be expanded on the host.</p>
<pre><code>kubectl exec $POD_ID  -- /bin/bash -c '
     printenv DATABASE_HOST_NAME
     echo $DATABASE_HOST_NAME
     psql -h $DATABASE_HOST_NAME -U DATABASE_USER
'
</code></pre>
