开发者

How can I select the filename with the highest version number?

开发者 https://www.devze.com 2023-01-23 13:07 出处:网络
I wrote a build script and would like to be able to select the latest version of the script when it installs, e.g. the package name is package_X.X.X.tar.gz and there are multiple copies.

I wrote a build script and would like to be able to select the latest version of the script when it installs, e.g. the package name is package_X.X.X.tar.gz and there are multiple copies.

开发者_Go百科Is there a way to point the build command to package_Y.tar.gz? where Y=max(X.X.X)?


If the files are equal except for the version numbers, you could use something like

ls -v | tail -n 1

From the man-page of ls:

...
-v     natural sort of (version) numbers within text
...

Example usage:

$ ls
package_1.5.7.9.tar.gz  package_2.5.3.9.tar.gz  package_4.6.1.0.tar.gz
$ ls -v | tail -n 1
package_4.6.1.0.tar.gz
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号