如何检查变量是否包含 c shell 中的子字符串?

How check if variable contains substring in c shell?

我正在尝试检查变量是否包含特定子字符串。测试值为"test_tpTest171_ess"

 if ($test =~ "Test171") then
    echo "statement is working"

也尝试过:

 $test == "*Test171*"
 $test == *Test171*

如果您使用了正确的运算符,您也尝试过 的方法将会奏效。

=~ 右侧的 glob-pattern 必须匹配整个左侧操作数,因此如果您希望在 Test171,您必须在此处添加 *

if ($test =~ *Test171*) echo "statement is working"