<p>I have been searching but I cannot find answer to my question.</p>
<p>What I am trying to do is to connect to remote shell of openshift container and create db dump, which works if i put username,password and db name by hand (real values).</p>
<p>I wish to execute this command to access env variables: (this command later will be part of bigger script)</p>
<pre><code> oc rsh mon-rs-nr-0 mongodump --host=rs/mon-rs-nr-0.mon-rs-nr.xxx.svc.cluster.local,mon-rs-nr-1.xxx.svc.cluster.local,mon-rs-nr-2.mon-rs-nr.xxx.svc.cluster.local --username=$MONGODB_USER --password=$MONGODB_PASSWORD --authenticationDatabase=$MONGODB_DATABASE
</code></pre>
<p>But it is not working, I also tried different versions with echo etc. (env vars are not replaced to they values). Env vars are present inside container.</p>
<p>When I try</p>
<pre><code>oc rsh mon-rs-nr-0 echo &quot;$MONGODB_PASSWORD&quot;
</code></pre>
<p>I recieve</p>
<pre><code>$MONGODB_PASSWORD
</code></pre>
<p>But when i firstly connect to container and then execute command:</p>
<pre><code>C:\Users\xxxx\Desktop&gt;oc rsh mon-rs-nr-0
$ echo &quot;$MONGODB_PASSWORD&quot;
mAYXXXXXXXXXXX
</code></pre>
<p>It works. However I need to use it in a way I presented at the top, do somebody know workaround?</p>

<p>Thanks to @msaw328 comment here is solution:</p>
<pre><code>C:\Users\xxx\Desktop&gt;oc rsh mon-rs-nr-0  bash -c &quot;mongodump --host=rs/mon-rs-nr-0.mon-rs-nr.xxx.svc.cluster.local,mon-rs-nr-1.mon-rs-nr.xxx.svc.cluster.local,mon-rs-nr-2.mon-rs-nr.xxx.svc.cluster.local --username=$MONGODB_USER --password=$MONGODB_PASSWORD --authenticationDatabase=$MONGODB_DATABASE&quot;
</code></pre>
<p>Output:</p>
<pre><code>Defaulted container &quot;mongodb&quot; out of: mongodb, mongodb-sidecar, mongodb-exporter

2021-08-20T11:01:12.268+0000    writing xxx.yyy to
2021-08-20T11:01:12.269+0000    writing xxx.ccc to
2021-08-20T11:01:12.269+0000    writing xxx.ddd to
2021-08-20T11:01:12.269+0000    writing xxx.eee to
2021-08-20T11:01:12.339+0000    done dumping xxx.eee (11 documents)
2021-08-20T11:01:12.339+0000    writing xxx.zzz to
2021-08-20T11:01:12.340+0000    done dumping xxx.ccc (24 documents)
2021-08-20T11:01:12.340+0000    writing xxx.bbb to
2021-08-20T11:01:12.340+0000    done dumping xxx.ddd (24 documents)
2021-08-20T11:01:12.340+0000    writing xxx.fff to
2021-08-20T11:01:12.436+0000    done dumping xxx.yyy (1000 documents)
2021-08-20T11:01:12.436+0000    writing xxx.ggg to
2021-08-20T11:01:12.436+0000    done dumping xxx.bbb (3 documents)
2021-08-20T11:01:12.437+0000    writing xxx.aaa to
2021-08-20T11:01:12.441+0000    done dumping xxx.fff (0 documents)
2021-08-20T11:01:12.441+0000    done dumping xxx.zzz (3 documents)
2021-08-20T11:01:12.447+0000    done dumping xxx.aaa(0 documents)
2021-08-20T11:01:12.449+0000    done dumping xxx.ggg (0 documents)
</code></pre>
