title: How do I escape awk's built-in variables when used within heredoc
body: <p>Following is the command I am trying to execute :</p>
  
  <pre><code>while read api; do
  echo $api
  ssh username@ip &lt;&lt;ENDSSH
  grep $api /myserver/logs/server.log | awk '{print $8}'| sort -n | awk 'BEGIN{i=0} {s[i]=$1; i++;} END{print "=== PERCENTILES ==="; print "50: " s[int(NR*0.50-0.5)]; print "70: " s[int(NR*0.70-0.5)]; print "80: " s[int(NR*0.80-0.5)]; print "90: " s[int(NR*0.90-0.5)]; print "95: " s[int(NR*0.95-0.5)]; print "99: " s[int(NR*0.99-0.5)]; print "100: " s[int(NR-1)]; print "Count:" NR; print "==================="}'
  ENDSSH
  done &lt;apiList &gt;output.out
  </code></pre>
  
  <p>I want to run this for multiple apis on a remote host and collect the output in an output file locally.
  list of files is locally stored.</p>
  
  <p>Initially I was using &lt;&lt;'ENDSSH' then $api wasn't getting evaluated.
  now I changed that to &lt;
  
  <p>How do I tell the remote host to evaluate NR?</p>