title: Bash - bad assignment value to variable
body: <p>I want to do a very simple script: just want to find the newest version of a program, say svn, on my computer. I want to load the result into a variable, say mysvn</p>
  
  <p>So I make this script:</p>
  
  <pre><code>
  #!/bin/sh
  
  mysvn="foobar"
  best_ver=0
  which -a svn | while read p
  do
      version=$("$p" --version | grep 'version ' | grep -oE '[0-9.]+' | head -1)
      if [[ "$version" > "$best_ver" ]]
      then
          best_ver=$version
          mysvn="$p"
      fi
      echo $mysvn
  done
  
  echo $mysvn
  </code></pre>
  
  <p>Very simple in fact ... but it does not work under rxvt (my pseudo-linux terminal), version 2.7.10, running under XP: the final output string is foobar.</p>
  
  <p>Does anybody know why I have this problem?</p>
  
  <p>I have been writing some scripts for the past few months, it is the first time I encounter such a behaviour.</p>
  
  <p>Note: I know how to make it work, with a few changes (just put the main lines into $() )</p>