else echo "Strings are not equal." fi 2. 使用 tr 命令去除所有空白字符 代码语言:txt 复制 string1=$(echo "your_string" | tr -d '[:space:]') string2=$(echo "your_string" | tr -d '[:space:]') if [ "$string1" == "$string2" ]; then echo "Strings are equal." else echo ...
-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. 判定字符串的数据 test -z string 判定字符串是否为 0 ?若 string 为空字符串,...
= STRIN2 # Trueifstrings arenotequal#算术测试操作var1 -eq var2 # Trueifvar1 is equal to var2var1 -ne var2 # Trueifvar1notequal to var2var1 -lt var2 # Trueifvar1 is less than var2var1 -le var2 # Trueifvar1 is less thanorequal ...
string1="apples" string2="oranges" 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 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" ...
public static boolean equals(String str1, String str2) Compares two Strings, returning true if they are equal. nulls are handled without exceptions. Two null references are considered to be equal. The comparison is case sensitive. StringUtils.equals(null, null) = true ...
echo "INT is not an integer." >&2 exit 1 fi只要是算术表达式,都能用于((...))语法,详见《Bash 的算术运算》一章。普通命令的逻辑运算如果if结构使用的不是test命令,而是普通命令,比如上一节的((...))算术运算,或者test命令与普通命令混用,那么可以使用 Bash 的命令控制操作符&&(AND)和||(OR),进行...
[ STRING1 > STRING2 ] 如果 “STRING1” sorts after “STRING2” lexicographically in the current locale则为真。 [ 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, ...
[zexcon@fedora ~]$ ./learnToScript.sh numberTwelve variable is equal to 12 你所看到的是if语句的第一行,它在检查变量的值是否真的等于12。如果是的话,语句就会停止,并发出numberTwelve is equal to 12的回显,然后在fi之后继续执行你的脚本。如果变量大于12的话,就会执行elif语句,并在fi之后继续执行。当...
Checking if two Bash script strings are equal isn’t a big thing per se, and even if the Bash script strings are not equal, that’s not also a big thing. This article explains everything you need to know about Bash string equality, plus how you can access and use Linux files on Win...