在 Shell 中,可以使用 =
运算符来判断两个字符串是否相等。例如:
#!/bin/bash
string1="hello"
string2="world"
if [ "$string1" = "$string2" ]
then
echo "The strings are equal."
else
echo "The strings are not equal."
fi
输出结果为:
The strings are not equal.
在这个例子中,我们定义了两个字符串 string1
和 string2
,并使用 =
运算符将它们进行比较。由于这两个字符串不相等,因此输出结果为 "The strings are not equal."
未经允许不得转载:国外服务器评测 » shell如何判断比较两个字符串是否相等