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 ...
str1 - the first String, may be null str2 - the second String, may be null Returns: 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" =...
string2="oranges" if [ "$string1" = "$string2" ]; then echo "The two strings are equal." else echo "The two strings are not equal." fi 这是我们执行脚本时的结果: $ ./test.sh The two strings are not equal. 例2 我们还可以使用运算符来测试两个字符串是否不相等!=。 #!/bin/bash...
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 我们还可以使用运算符来...
$ ./test.sh The two strings are not equal. 1. 2. 例2 我们还可以使用运算符来测试两个字符串是否不相等!=。 #!/bin/bash string1="apples" string2="oranges" if [ "$string1" != "$string2" ]; then echo "Strings are different." ...
test EXPRESSION [ EXPRESSION ] [[ EXPRESSION ]] 1. 2. 3. 前两种是等价的,应该是没有区别的。注意EXPRESSION两边与中括号之间需要有空格。 双中括号与前两者的区别,主要在于表达式中的操作符如果是这种情况的时候。 [[ string1 > string2 ]]
test EXPRESSION [ EXPRESSION ] [[ EXPRESSION ]] 前两种是等价的,应该是没有区别的。注意EXPRESSION两边与中括号之间需要有空格。 双中括号与前两者的区别,主要在于表达式中的操作符如果是这种情况的时候。 [[ string1 >string2 ]] [[ string1< string2 ]] ...
/bin/bashstring1="apples"string2="oranges"if["$string1"="$string2"];thenecho"Thetwostringsareequal."elseecho"Thetwostringsarenotequal."fi 这是我们执行脚本时的结果: $./test.shThetwostringsarenotequal. 例2 我们还可以使用运算符来测试两个字符串是否不相等!=。
is readable-s FILE_NAM # TrueifFILE_NAM existsandisnotempty-w FILE_NAM # TrueifFILE_NAM has write permission-x FILE_NAM # TrueifFILE_NAM is executable#字符串测试操作-z STRING # TrueifSTRING is empty-n STRING # TrueifSTRING isnotemptySTRING1...
格式: test 判断表达式 根据命令的返回代码确定表达式为真还是为假。返回代码为0,表达式为真,返回代码为1,则表达式为假。 1)整数逻辑判断 test 3 -gt 2; echo $? #大于 -gt great than test 3 -lt 2; echo $? #小于 -lt less than test 3 -eq 3; echo $? #等于 -eq equal test 3 -ne 1;...