如何使用Shell判断版本号的大小

如果你想通过shell来比较两个版本号字符串,比如两个版本号1.1.2和1.2.1这两个版本谁是比较新的。

最简单的就是使用sort命令。加上参数"-V"后sort命令就可以把文本中的版本号给排序出来(默认是递增的排序),然后你想倒序排序的话那就使用参数"-rV"即可。

参考链接:http://www.linuxdown.net/install/faq/20160319_how_linux_5069.html

原文地址:https://www.cnblogs.com/jxst441192/p/9457063.html

时间: 2024-12-30 12:44:55

如何使用Shell判断版本号的大小的相关文章

javascript通用判断版本号是否在版本范围之间代码

通用判断版本号是否在两者之间,也可以搭配判断是否大于某版本号,小于取反即可 1 var APP = {}; 2 3 //判断指定版本是否在版本范围之间 1.0.2 3.1.6 4 APP.betweenVersion = function(curr,start,end,separator){ 5 if(curr == start || curr == end){ 6 return true; 7 } 8 9 var separator = separator || '.'; 10 var cur

shell 判断文件、目录是否存在

shell判断文件是否存在 1. shell判断文件,目录是否存在或者具有权限 2. #!/bin/sh 3. 4. myPath="/var/log/httpd/" 5. myFile="/var /log/httpd/access.log" 6. 7. # 这里的-x 参数判断$myPath是否存在并且是否具有可执行权限 8. if [ ! -x "$myPath"]; then 9. mkdir "$myPath" 10

shell判断条件是否存在

1. shell判断文件,目录是否存在或者具有权限 2. #!/bin/sh 3. 4. myPath="/var/log/httpd/" 5. myFile="/var /log/httpd/access.log" 6. 7. # 这里的-x 参数判断$myPath是否存在并且是否具有可执行权限 8. if [ ! -x "$myPath"]; then 9. mkdir "$myPath" 10. fi 11. 12. #

[SHELL]判断一个命令是否存在

首先要说明的是,不要使用which来进行判断,理由如下: 1.which非SHELL的内置命令,用起来比内置命令的开销大,并且非内置命令会依赖平台的实现,不同平台的实现可能不同. # type type type is a shell builtin # type command command is a shell builtin # type which which is hashed (/usr/bin/which) 2.很多系统的which并不设置退出时的返回值,即使要查找的命令不存在,

shell判断文件是否存在

转自:http://www.cnblogs.com/sunyubo/archive/2011/10/17/2282047.html 1. shell判断文件,目录是否存在或者具有权限 2. #!/bin/sh 3. 4. myPath="/var/log/httpd/" 5. myFile="/var /log/httpd/access.log" 6. 7. # 这里的-x 参数判断$myPath是否存在并且是否具有可执行权限 8. if [ ! -x "

shell判断一个变量是否为空

判断一个变量是否为空 . 1. 变量通过" "引号引起来 如下所示:,可以得到结果为 IS NULL. #!/bin/sh para1= if [ ! -n "$para1" ]; then echo "IS NULL" else echo "NOT NULL" fi 2. 直接通过变量判断 如下所示:得到的结果为: IS NULL #!/bin/sh para1= if [ ! $para1 ]; then echo &qu

[转] Linux shell判断文件和文件夹是否存在

shell判断文件,目录是否存在或者具有权限 #!/bin/sh myPath="/var/log/httpd/" myFile="/var /log/httpd/access.log" #这里的-x 参数判断$myPath是否存在并且是否具有可执行权限 if [ ! -x "$myPath"]; then mkdir "$myPath" fi #这里的-d 参数判断$myPath是否存在 if [ ! -d "$m

shell判断文件类型和权限

shell  判断文件类型. -d 文件 判断该文件是否存在,并且是否为目录(是目录为真) -e文件 判断该文件是否存在(存在为真) -f文件 判断该文件是否存在,并且是否为文件(是普通文件为真) -r 如果有文件存在 ,判断文件是否具有读权限有读权限返回真-w如果有文件存在 ,判断文件是否具有写权限有写权限返回真-x如果有文件存在 ,判断文件是否具有执行权限有执行权限返回真 在shell中的写法一般是 eg:[空格-e 文件路径 空格] [ -e /tmp/index.php ] [ -e /

shell判断和比较

http://blog.chinaunix.net/uid-7553302-id-183648.html 1  shell 的$! ,$?, $$,[email protected] $n        $1 the first parameter,$2 the second... $#        The number of command-line parameters. $0        The name of current program. $?        Last comma