如何比较Bash中的字符串如何将变量与字符串进行比较(如果它们匹配,则执行一些操作)?
3 回答
繁花不似锦
TA贡献1851条经验 获得超4个赞
a="abc"b="def"# Equality Comparisonif [ "$a" == "$b" ]; then echo "Strings match"else echo "Strings don't match"fi# Lexicographic (greater than, less than) comparison.if [ "$a" \< "$b" ]; then echo "$a is lexicographically smaller then $b"elif [ "$a" \> "$b" ]; then echo "$b is lexicographically smaller than $a"else echo "Strings are equal"fi
注:
之间的空间 if和 [和 ]很重要 >和 <是重定向操作符吗? \>和 \<分别用于字符串。
添加回答
举报
0/150
提交
取消
