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

前端 未结 29 1321
慢半拍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条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-11-22 07:12

    GNU sort has an option for it:

    printf '2.4.5\n2.8\n2.4.5.1\n' | sort -V
    

    gives:

    2.4.5
    2.4.5.1
    2.8
    

提交回复
热议问题