shell script if condition

来源:互联网 发布:python搭建webservice 编辑:程序博客网 时间:2024/05/29 04:28

There are many different ways that an conditional statement can be used. These are summarized here:

String ComparisonDescriptionStr1 = Str2Returns true if the strings are equalStr1 != Str2Returns true if the strings are not equal-n Str1Returns true if the string is not null-z Str1Returns true if the string is nullNumeric ComparisonDescriptionexpr1 -eq expr2Returns true if the expressions are equalexpr1 -ne expr2Returns true if the expressions are not equalexpr1 -gt expr2Returns true if expr1 is greater than expr2expr1 -ge expr2Returns true if expr1 is greater than or equal to expr2expr1 -lt expr2Returns true if expr1 is less than expr2expr1 -le expr2Returns true if expr1 is less than or equal to expr2! expr1Negates the result of the expressionFile ConditionalsDescription-d fileTrue if the file is a directory-e fileTrue if the file exists (note that this is not particularly portable, thus -f is generally used)-f fileTrue if the provided string is a file-g fileTrue if the group id is set on a file-r fileTrue if the file is readable-s fileTrue if the file has a non-zero size-uTrue if the user id is set on a file-wTrue if the file is writable-xTrue if the file is an executable
0 0
原创粉丝点击