[ ARG1 OP ARG2 ] “OP” is one of -eq, -ne, -lt, -le, -gt or -ge. These arithmetic binary operators return true if “ARG1” is equal to, not equal to, less than, less than or equal to, greater than, or greater
[ ARG1 OP ARG2 ] “OP” is one of -eq, -ne, -lt, -le, -gt or -ge. These arithmetic binary operators return true if “ARG1” is equal to, not equal to, less than, less than or equal to, greater than, or greater than or equal to “ARG2”, respectively. “ARG1” and “AR...
A -ne B: 不等于 not equal to 2.3 字符串测试:A, B A > B A < B A >= B A <= B A == B或A = B:等值比较 A != B: 不等于 -z A: 判断A是否为空;空则为真,不空则假; -n A:判断A是否不空;不空则为真,空则为假; =~ "$A" =~ PATTERN 如果变量A中保存的字符串能被PATTERN...
if [ "$string1" = "$string2" ]; then echo "The two strings are equal." else echo "The two strings are not equal." fi 这是我们执行脚本时的结果: 代码语言:txt AI代码解释 $ ./test.sh The two strings are not equal. 例2 我们还可以使用运算符来测试两个字符串是否不相等!=。 代码语言...
ne 不等于 not equal ge 大于等于 greater or equal le 小于等于 less or equal 注意: 每一个选项前须要有一个短横线-。 还要注意的是使用以上操作符,那么操作符两边一定要是整数。 在Bash中,即使给整数加了引號。比方"123",也视作整数。但假设某一位含有整数[0-9]以外的字符比方。12a,"12a",则不行。
-ne not equal 不等 -eq equal 等于 -ge greater or equal 大于或等于 -lt less than 小于 字符测试 == 是否等于 > 是否大于 < 是否小于 != 是否不等于 =~ 左侧字符串能否被右侧的模式所匹配 -z 判断指定的字符串是否为空,空为真,不空为假 ...
-ne 即-Not Equal的缩写,表示不等于 -o 即-or,表示前后二个逻辑判断是『或』的关系,类似的 -a 即-and,表示前后二个逻辑判断是『与』的关系 elif 即else if的缩写 上面的示例运行结果: 代码语言:javascript 代码运行次数:0 运行 AI代码解释 ./demo.sh90+i=90+test90-gt89+echoAA ...
-eq(equal) 检测两个数是否相等,相等则返回 true -ne(not equal) 检测两个数是否相等,不相等则返回 true -gt(greater than) 检测左边的数是否大于右边的,如果是,则返回 true -lt(lower than) 检测左边的数是否小于右边的,如果是,则返回 true -ge(greater equal) 检测左边的数是否大于等于右边的,如果是,则...
TestFile1 does not exist or is empty. 向文件添加一些内容,然后再测试一次: [student@studentvm1 testdir]$ File="TestFile1" ; echo "This is file $File" > $File ; if [ -s $File ] ; then echo "$File exists and contains data." ; else echo "$File does not exist or is empty." ...
The two strings are not equal. 1. 2. 例2 我们还可以使用运算符来测试两个字符串是否不相等!=。 #!/bin/bash string1="apples" string2="oranges" if [ "$string1" != "$string2" ]; then echo "Strings are different." else echo "Strings are not different." ...