How to send a string with spaces from Python to Bash sub-process as a single value?
<p>I'm trying to send a variable from a python script to a bash script. I'm using <code>popen</code> like as shown below:</p>

<pre><code>subprocess.Popen(["bash", "-c", ". mainGui_functions.sh %d %s" % (commandNum.get(), entryVal)])
</code></pre>

<p>However, <code>entryVal</code> can sometimes contain one or more white space characters. In that case I divide the string into multiple arguments ($2,$3..)</p>

<p>How can i get it in one argument?</p>

<p>Put quotes around it in your bash command line â e.g.,</p>

<pre><code>subprocess.Popen(['bash', '-c', '. mainGui_functions.sh %d "%s"' % (commandNum.get(), entryVal)])
</code></pre>

python bash subprocess