title: Awk and a global variable
body: <p>Good, why can't I pass the value of the variable numIterations to the next expression and instead if it works for me if I put the value by hand?</p>
  
  <pre><code>echo "numIterations $numIterations"
  (tr ' ' '\n' | sort | uniq -c | awk '{print "winner " $2 " appeared "$1 " times. Frequency is "$1*100 / $numIterations" %"}') &lt; "final_winners.txt" &gt; "final_output_winners.txt"
  </code></pre>
  
  <p>This is the output below:</p>
  
  <pre><code>numIterations 1000
  winner 10 appeared 110 times. Frequency is 100 %
  winner 11 appeared 90 times. Frequency is 100 %
  ...
  </code></pre>
  
  <p>$1 is 110, $numIterations is 1000, so the result must be 11%, no 100%</p>
  
  <p>If i substitute $numIterations with 1000, the result is ok.</p>
  
  <p>I am running bash 3.2 in osx 10.14.1.
  Thank you.</p>