title: Different behavior in bash string comparison while inside a function
body: <p>There's the following part in a shell script I'm writing:  </p>
  
  <p>(Find the latest directory in <code>someDir</code> which is not <code>summary/</code>)</p>
  
  <pre><code>latestDirName=""
  for dirName in `ls -lt /user/someDir/ | head -3 | tail -n +2 | awk '{print $9}'`
    do
      if [ "$dirName" == "summary" ]; then
        continue
      fi
      latestDirName=$dirName
    done
  </code></pre>
  
  <p>Here <code>$dirname</code> is compared against string <code>summary</code>, while an echo of <code>dirName</code> variable during the iteration will print as <code>summary/</code>  </p>
  
  <p>This comparison part works all fine when the code is written in a file and executed.   </p>
  
  <p>But once this same code is put inside a function and placed in my bashrc, the comparison in <code>if</code> check doesn't seem to work!  </p>
  
  <p>Does this have anything to do with the string being a directory name, or it having the <code>/</code>?<br>
  What difference does it make when the same code is inside a function?  </p>
  
  <p>Code inside bashrc:  </p>
  
  <pre><code>findLatestDir()
  {
    latestDirName=""
    for dirName in `ls -lt /user/someDir/ | head -3 | tail -n +2 | awk '{print $9}'`
      do
        if [ "$dirName" == "summary" ]; then
          continue
        fi
        latestDirName=$dirName
      done
  }
  </code></pre>
  
  <p>The scripts are called as follows:<br>
  Case #1 (code in file): <code>$ ./findLatestDir.sh</code><br>
  Case #2 (function in bashrc): <code>$ findLatestDir</code></p>