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

前端 未结 29 1786
慢半拍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

    This is for at most 4 fields in the version.

    $ function ver { printf "%03d%03d%03d%03d" $(echo "$1" | tr '.' ' '); }
    $ [ $(ver 10.9) -lt $(ver 10.10) ] && echo hello  
    hello
    

提交回复
热议问题