跳至主要內容
  • Hostloc 空間訪問刷分
  • 售賣場
  • 廣告位
  • 賣站?

4563博客

全新的繁體中文 WordPress 網站
  • 首頁
  • bash 判断 Ubuntu 版本是否大于 18.04
未分類
21 2 月 2021

bash 判断 Ubuntu 版本是否大于 18.04

bash 判断 Ubuntu 版本是否大于 18.04

資深大佬 : sudoy 5

就是想通过 .sh 文件判断 Ubuntu 版本是否高于 18.04 。搜了半天没找到合适的,下面这个还是错的。哪位大佬帮忙改下

VER=$(lsb_release --release | cut -f2)  if [ "$VER > 18.04" | bc ]; then         echo "Ubuntu version is greater than 18" else         echo "Ubuntu version is less than 18" exit 0 fi 

大佬有話說 (7)

  • 資深大佬 : love

    python -c “print($VER > 18.04)” | grep True && {
    echo OK
    }

  • 資深大佬 : Xusually

    #cat ver.sh

    function version { echo “[email protected]” | awk -F. ‘{ printf(“%d%03d%03d%03dn”, $1,$2,$3,$4); }’; }

    VER=$(lsb_release –release | cut -f2)

    if [ $(version $VER) -ge $(version “18.04”) ]; then
    echo “Ubuntu version is greater than 18”
    else
    echo “Ubuntu version is less than 18”
    fi

    # chmod +x ver.sh
    # ./ver.sh
    Ubuntu version is greater than 18

  • 資深大佬 : miscnote

    just my way:
    perl -e ‘open $fd,”/etc/issue”;$str=<$fd>;($ver)=$str=~/(d+.d+.d+)/;print “true” if $ver>18.04’

  • 資深大佬 : Xusually

    # lsb_release –release
    Release: 20.04

  • 主 資深大佬 : sudoy

    @Xusually 感谢!我测试了这个方案可行的!

  • 主 資深大佬 : sudoy

    @love @miscnote 两位这个方法好像是要依赖于 python 和 perl,我想要纯 bash 脚本的

  • 資深大佬 : taolu

    test $(echo “$VER > 18.04” | bc) -eq 1 && echo “Ubuntu version is greater than 18” || echo “Ubuntu version is less than 18”

文章導覽

上一篇文章
下一篇文章

AD

其他操作

  • 登入
  • 訂閱網站內容的資訊提供
  • 訂閱留言的資訊提供
  • WordPress.org 台灣繁體中文

51la

4563博客

全新的繁體中文 WordPress 網站
返回頂端
本站採用 WordPress 建置 | 佈景主題採用 GretaThemes 所設計的 Memory
4563博客
  • Hostloc 空間訪問刷分
  • 售賣場
  • 廣告位
  • 賣站?
在這裡新增小工具