How to compare two strings in dot separated version format in Bash?

前端 未结 29 1350
慢半拍i
慢半拍i 2020-11-22 06:52

Is there any way to compare such strings on bash, e.g.: 2.4.5 and 2.8 and 2.4.5.1?

29条回答
  •  难免孤独
    2020-11-22 07:19

    if it's just about to know whether one version is lower than another I came up checking whether sort --version-sort changes the order of my version strings:

        string="$1
    $2"
        [ "$string" == "$(sort --version-sort <<< "$string")" ]
    

提交回复
热议问题