<p>I'm trying to run mongo commands through my bash script file.</p>
<p>I have sample.sh -- run with ./sample.sh</p>
<p>I want to run below command inside my sample.sh file. It is bash script.
I want to mongo commands run inside the file, not inside the shell.</p>
<pre><code>kubectl exec $mongoPodName -c mongo-mongodb -- mongo db.createUser({user:&quot;admin&quot;,pwd:&quot;123456&quot;,roles:[{role:&quot;root&quot;,db:&quot;admin&quot;}]})

</code></pre>
<p>I get the error below :</p>
<pre><code>./generate-service-dbs.sh: line 37: syntax error near unexpected token `('
./generate-service-dbs.sh: line 37: `kubectl exec $mongoPodName -c mongo-mongodb -- mongo db.createUser({user:&quot;admin&quot;,pwd:&quot;123456&quot;,roles:[{role:&quot;root&quot;,db:&quot;admin&quot;}]})'


</code></pre>

Hakimeh Mordadi
<p>Don't you have to run command with <code>--eval</code>?</p>
<pre class="lang-bash prettyprint-override"><code>kubectl exec $mongoPodName -c mongo-mongodb -- mongo --eval 'db.createUser({user:&quot;admin&quot;,pwd:&quot;123456&quot;,roles:[{role:&quot;root&quot;,db:&quot;admin&quot;}]})'

</code></pre>
