Passing arguments to Python from Shell Script
<p>I wrote a small shell script that looks like:</p>

<pre><code>cd models/syntaxnet
var1=$(jq --raw-output '.["avl_text"]' | syntaxnet/demo.sh)
echo $var1
python /home/sree/python_code1.py $var1
</code></pre>

<p>My <code>python_code1.py</code> looks like:</p>

<p>import sys</p>

<pre><code>data = sys.argv[1]
print "In python code"
print data
print type(data)
</code></pre>

<p>Now, the output of echo $var1 in my shell script is exactly what I wanted to see:</p>

<p><code>1 Check _ VERB VB _ 0 ROOT _ _ 2 out _ PRT RP _ 1 prt _ _ 3 this _ DET DT _ 4 det _ _ 4 video _ NOUN NN _ 1 dobj _ _ 5 about _ ADP IN _ 4 prep _ _ 6 Northwest _ NOUN NNP _ 7 nn _ _ 7 Arkansas _ NOUN NNP _ 5 pobj _ _ 8 - _ . , _ 7 punct _ _ 9 https _ X ADD _ 7 appos _ _</code></p>

<p>But the output of <code>print data</code> in the python code is jus <code>1</code>. i.e. the first letter of the argument.</p>

<p>Why is this happening? I want to pass the entire string to the python code.</p>

<p>Use Join and list slicing</p>

<pre><code>import sys
data = ' '.join(sys.argv[1:])
print "In python code"
print data
print type(data)
</code></pre>

python shell arguments