On 06/09/2010 05:29 PM, Amadeusz Żołnowski wrote:
--- dracut-functions | 23 ++++++++++++----------- 1 files changed, 12 insertions(+), 11 deletions(-) diff --git a/dracut-functions b/dracut-functions index fbac282..500e3ae 100755 --- a/dracut-functions +++ b/dracut-functions @@ -27,19 +27,20 @@ strstr() { [[ $1 =~ $2 ]]; } # Version comparision function. Returns result similar to C strcmp, # but instead of -1 is 2. Function assumes version scheme like does # Linux kernel. +# $1< $2 -> 2 +# $1 = $2 -> 0 +# $1> $2 -> 1 +# To remember it easy, ask the question: Which argument is greater? ;-) vercmp() { - local n1 n2 i=1 - - while true - do - n1=$(echo $1 | cut -d'.' -f$i) - n2=$(echo $2 | cut -d'.' -f$i) - - [[ ! $n1&& ! $n2 ]]&& return 0 - [[ $n1 -lt $n2 ]]&& return 2 - [[ $n1 -gt $n2 ]]&& return 1 - - ((i++)) + local i n1=(${1//./ }) n2=(${2//./ }) + + for ((i=0; ; i++)) + do + [[ ${n1[i]}&& ! ${n2[i]} ]]&& return 1 + [[ ! ${n1[i]}&& ${n2[i]} ]]&& return 2 + [[ ${n1[i]}&& ${n2[i]} ]] || return 0 + ((${n1[i]}> ${n2[i]}))&& return 1 + ((${n1[i]}< ${n2[i]}))&& return 2 done }
pushed -- To unsubscribe from this list: send the line "unsubscribe initramfs" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html