在bash脚本中实现版本检查

时间:2011-01-26 08:20:13

标签: bash curl

我想在bash脚本中实现版本检查,这将验证我网站上的文件,然后如果脚本的版本与上一版本不匹配,则会打开一个网页。我听说我会使用cURL,但没有找到关于我的案例的任何tuto。

1 个答案:

答案 0 :(得分:0)

我要写下我要做的事情:

#configuration
VERSION=1.0.0
URL='http://example.com/version'
DL_URL='http://example.com/download'
#later on whenever you want
# Assume the url only displays the current version number
CHECK_VERSION=$(wget -O- "$URL")
# If you remove the periods, it works as a way to
# lexicorigraphically compare the version numbers as numbers
CURRENT_NUMBER=$(echo "$VERSION" | tr -d '.')
NEW_NUMBER=$(echo "$CHECK_VERSION" | tr -d '.')
test "$CURRENT_NUMBER" -gt "$NEW_NUMBER" || x-www-browser "$DL_URL"