[英]Programmatically detect whether current Ubuntu version is lower or greater than Ubuntu 12.04
我正在研究java web應用程序,其中邏輯將根據os版本而不同。
目前我們在Ubuntu 12.04和Ubuntu 10上部署我們的應用程序.Web App允許通過其UI更改DNS名稱服務器。 部署在Ubuntu 10中的應用程序將DNS名稱服務器保存在etc/resolv.conf
但Ubuntu 12.04將它們保存在etc/network/interfaces
。
存儲DNS名稱服務器時,邏輯就像
if(ubuntuVersion < ubuntu 12.04) then
store it in etc/resolv.conf
else
store it in etc/network/interfaces.
System.getProperty("os.name")
或System.getProperty("os.arch")
或任何其他系統屬性不輸出Ubuntu包信息。
如何實施if
部分?
嘗試命令lsb-release
,它應該返回發行版的發布版本。 您應該能夠從輸出中提取版本。
正好跑
lsb_release --release --short
將返回ubuntu版本號
您可以通過以下方式獲得操作系統版
lsb_release -a|grep Release|cut -f2
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.