我在Bash中有一个字符串:
string="My string"
Run Code Online (Sandbox Code Playgroud)
如何测试它是否包含另一个字符串?
if [ $string ?? 'foo' ]; then
echo "It's there!"
fi
Run Code Online (Sandbox Code Playgroud)
??
我的未知运营商在哪里?我是否使用echo grep
?
if echo "$string" | grep 'foo'; then
echo "It's there!"
fi
Run Code Online (Sandbox Code Playgroud)
这看起来有点笨拙.