title: In bash, how do I count the number of lines in a variable?
body: <p>I have a variable which has a string stored in it and need to check if it has lines in it:</p>
  
  <pre><code>var=`ls "$sdir" | grep "$input"`
  </code></pre>
  
  <p>pseudo-code:</p>
  
  <pre><code>while [ ! $var's number of lines -eq 1 ]
    do something
  </code></pre>
  
  <p>That's my idea on how to check it. <code>echo $var | wc -l</code> doesn't work - it always says <code>1</code>, even though it has <code>3</code>.</p>
  
  <p><code>echo -e</code> doesn't work as well.</p>