4. 关于两个整数之间的判定,例如 test n1 -eq n2 -eq 两数值相等 (equal) -ne 两数值不等 (not equal) -gt n1 大于 n2 (greater than) -lt n1 小于 n2 (less than) -ge n1 大于等于 n2 (greater than or equal) -le n1 小于等于 n2 (less than or equal) 5.
数值测试:数值比较 -eq:是否等于(equal) -ne:是否不等于(not equal) -gt:是否大于(greater than) -ge:是否大于等于(greater equal) -lt:是否小于(little than) -le:是否小于等于(little equal) 数值测试示例 字符串测试:字符串要用引号引起来,最好使用[[ expression ]] ==:是否等于 !=:是否不等于 >:是...
echo "Strings are equal" else echo "Strings are not equal" fi 字符串不相等比较:使用叹号加双等号(!=)来比较两个字符串是否不相等。例如: 代码语言:txt 复制 str1="Hello" str2="World" if [ "$str1" != "$str2" ]; then echo "Strings are not equal" else echo "Strings are equal" fi ...
整数比较: -eq 测试两个整数是否相等,相等为真,不等为假。 equal -ne 测试两个整数是否不相等,不相等为真,否则为假 not equal -gt 测试一个整数是否大于另一个,大于为真,否则为假。 greater than -lt 测试一个速度是否小于另一个,小于为真,否则为假。 less than -ge 大于或等于 greater than or equal...
echo "equal" fi 下面是或运算符 -o,有一个为真就可以 if test $var1 != "1" -o $var2 != "3" ; then echo "not equal" fi 下面是非运算符 ! if条件是为真的时候执行,如果使用!运算符,那么原表达式必须为false if ! test $var1 != "1"; then ...
echo "The two strings are not equal." fi 这是我们执行脚本时的结果: 代码语言:txt AI代码解释 $ ./test.sh The two strings are not equal. 例2 我们还可以使用运算符来测试两个字符串是否不相等!=。 代码语言:txt AI代码解释 #!/bin/bash ...
-ne:不等于(not equal) -lt:小于(less than) -le:小于等于(less than or equal) -gt:大于(greater than) -ge:大于等于(greater than or equal) 循环:使用循环结构来重复执行一段代码。 for 循环:用于遍历列表或范围。 #!/bin/bash for i in 1 2 3 4 5 do echo $i done while 循环:在给定条件...
BashShell数字字符⽐较⼤⼩数字的⽐较:-eq 相等(equal)-ne 不等(not equal)-gt ⼤于(greater than)-lt ⼩于(less than)-ge ⼤于等于(greater than or equal)-le ⼩于等于(less than or equal)eg:if [ $max -gt $min ]字符串的⽐较:[ $str1 = $str2 ] 等于 [ $...
String1 and String3 are not equal. 这里,如果我们先用 = 运算符比较 String1 和 String2。由于 String1 和 String2 都具有相同的长度,具有相同的字符序列,比较运算符返回 true,因此我们得到 String1 and String2 are equal.. 作为程序中第一个 if-else 块的输出。
-eq:等于 (equal to) -ne:等于 (not equal to) -gt:大于 (greater than) -ge:大于或等于(greater than or equal to) -lt:小于 (less than) -le:小于或等于(less than or equal to) #!/usr/bin/env bash test 1 -eq 2 && echo "true" || echo "false" ...