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
So I make this script:
#!/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
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.
Does anybody know why I have this problem?
I have been writing some scripts for the past few months, it is the first time I encounter such a behaviour.
Note: I know how to make it work, with a few changes (just put the main lines into $() )