[ 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
-ne——不等于(not equal) -lt——小于(less than) -le——小于等于(less equal) -gt——大于(great than) -ge——大于等于(great equal) -f——文件(file) -d——目录(directory) (一)选择执行语句 单分支的if语句 if 测试条件;then fi 双分支的if语句 if 测试条件;then 如果满足条件就执行这里的...
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 我们还可以使用运算符来测试两个字符串是否不相等!=。 代码语言...
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...
#!/bin/bash # 示例1:使用 = 进行字符串相等比较 string1="hello" string2="hello" if [ "$string1" = "$string2" ]; then echo "The strings are equal." else echo "The strings are not equal." fi # 示例2:使用 != 进行字符串不相等比较 string1="hello" string2="world" if [ "$stri...
if [ "$str1" == "$str2" ]; then echo "Strings are equal" else echo "Strings are not equal" fi 字符串不相等比较:使用叹号加双等号(!=)来比较两个字符串是否不相等。例如: 代码语言:txt 复制 str1="Hello" str2="World" if [ "$str1" != "$str2" ]; then ...
-eq(equal) 检测两个数是否相等,相等则返回 true -ne(not equal) 检测两个数是否相等,不相等则返回 true -gt(greater than) 检测左边的数是否大于右边的,如果是,则返回 true -lt(lower than) 检测左边的数是否小于右边的,如果是,则返回 true -ge(greater equal) 检测左边的数是否大于等于右边的,如果是,则...
[ 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...
n1 -ne n2 检查n1是否不等于n2 (not equal) $ if test 5 -eq 5;then echo "YES"; else echo "NO"; fi #两数相等YES $ if test 5 -ne 5;then echo "YES"; else echo "NO"; fi #两数不相等NO 字符串测试 命令描述 str1 = str2 检查str1是否和str2相同 str1 != str2 检查str1是否和...
true if the Strings are equal, case insensitive, or both null In Bash 判断字符串相等 格式1:test "$S1" = "$S2" 格式2:[ "$S1" = "$S2" ] 格式3:test "$S1" == "$S2" 格式4:[ "$S1" == "$S2" ] 格式5:[[ $S1 = $S2 ]] ...