更新时间:2023-01-19 21:15:13
对于字符串相等比较,使用:
For string equality comparison, use:
if [[ "$s1" == "$s2" ]]
对于字符串不等于比较,使用:
For string does NOT equal comparison, use:
if [[ "$s1" != "$s2" ]]
对于a
包含b
,使用:
if [[ $s1 == *"$s2"* ]]
(并确保在符号之间添加空格):
(and make sure to add spaces between the symbols):
不好:
if [["$s1" == "$s2"]]
好:
if [[ "$s1" == "$s2" ]]