title: How to pass variables from python script to bash script
body: <p>I have a bash script, a.sh , and in it I have call a python script b.py .
  The python script calculates something, and I want it to return a value that will be used later in a.sh .
  I know I can do</p>
  
  <p>In a.sh:</p>
  
  <pre><code>var=`python b.py`
  </code></pre>
  
  <p>In b.py:</p>
  
  <pre><code>print x # when x is the value I want to pass
  </code></pre>
  
  <p>But this is not so convenient, because I also print other messages in b.py</p>
  
  <p>Is there any better way to do it?</p>
  
  <p><strong>Edit:</strong></p>
  
  <p>What I'm doing now is just </p>
  
  <pre><code>var=`python b.py | tail -n 1`
  </code></pre>
  
  <p>It means I can print many things inside b.py, but only the last line (the last print command, assuming it doesn't contain "\n" in it) will be stored in var.</p>
  
  <p>Thanks for all the answers!</p>