From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by mx.groups.io with SMTP id smtpd.web11.1921.1655177147384264282 for ; Mon, 13 Jun 2022 20:25:48 -0700 Authentication-Results: mx.groups.io; dkim=missing; spf=pass (domain: huawei.com, ip: 45.249.212.188, mailfrom: xiewenyi2@huawei.com) Received: from dggemv704-chm.china.huawei.com (unknown [172.30.72.53]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4LMYdw34MvzRjMR; Tue, 14 Jun 2022 11:22:28 +0800 (CST) Received: from kwepemm600004.china.huawei.com (7.193.23.242) by dggemv704-chm.china.huawei.com (10.3.19.47) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Tue, 14 Jun 2022 11:25:40 +0800 Received: from kwephisprg16640.huawei.com (10.247.83.252) by kwepemm600004.china.huawei.com (7.193.23.242) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Tue, 14 Jun 2022 11:25:40 +0800 From: "wenyi,xie" To: , , , CC: , Subject: [PATCH EDK2 v1 1/1] edksetup.sh:The version compare issue in shell script Date: Tue, 14 Jun 2022 11:25:34 +0800 Message-ID: <20220614032534.3386430-2-xiewenyi2@huawei.com> X-Mailer: git-send-email 2.18.0.huawei.25 In-Reply-To: <20220614032534.3386430-1-xiewenyi2@huawei.com> References: <20220614032534.3386430-1-xiewenyi2@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.247.83.252] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To kwepemm600004.china.huawei.com (7.193.23.242) X-CFilter-Loop: Reflected Content-Type: text/plain REF:https://bugzilla.tianocore.org/show_bug.cgi?id=3948 In function of SetupPython3, the version of python will be compared to get the new one. When python 3.10 is compared with python 3.4, the result is not right. Because the version number is treated as a float and 3.10 is smaller than 3.4. So using sort to arrange the version from old to new in order to get the new one. Cc: Andrew Fish Cc: Leif Lindholm Cc: Michael D Kinney Signed-off-by: Wenyi Xie --- edksetup.sh | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/edksetup.sh b/edksetup.sh index 06d2f041e635..b9da62440f71 100755 --- a/edksetup.sh +++ b/edksetup.sh @@ -20,6 +20,11 @@ SCRIPTNAME="edksetup.sh" RECONFIG=FALSE +function IsVersionGreaterThan() +{ + test "$(echo "$@" | tr " " "\n" | sort -V | head -n 1)" != "$1"; +} + function HelpMsg() { echo "Usage: $SCRIPTNAME [Options]" @@ -122,7 +127,7 @@ function SetupPython3() export PYTHON_COMMAND=$python continue fi - if [[ "$origin_version" < "$python_version" ]]; then + if IsVersionGreaterThan $python_version $origin_version; then origin_version=$python_version export PYTHON_COMMAND=$python fi @@ -164,7 +169,7 @@ function SetupPython() export PYTHON_COMMAND=$python continue fi - if [[ "$origin_version" < "$python_version" ]]; then + if IsVersionGreaterThan $python_version $origin_version; then origin_version=$python_version export PYTHON_COMMAND=$python fi -- 2.20.1.windows.1