title: set variable in heredoc section
body: <p>I'm a shell script newbie, so I must be doing something stupid, why won't this work:</p>
  
  <pre><code>#!/bin/sh
  
  myFile=$1
  
  while read line
  do
  ssh $USER@$line &lt;&lt;ENDSSH
  ls -d foo* | wc -l 
  count=`ls -d foo* | wc -l`
  echo $count
  ENDSSH
  done &lt;$myfile
  </code></pre>
  
  <p>Two lines should be printed, and each should have the same value... but they don't. The first print statement [the result of ls -d foo* | wc -l] has the correct value, the second print statement is incorrect, it always prints blank. Do I need to do something special to assign the value to $count?</p>
  
  <p>What am I doing wrong?</p>
  
  <p>Thanks</p>