I have a string in Bash: 我在Bash中有一个字符串: 测试
string="My string"
How can I test if it contains another string? 如何测试它是否包含另外一个字符串? spa
if [ $string ?? 'foo' ]; then echo "It's there!" fi
Where ??
哪里??
is my unknown operator. 是我未知的运算符。 Do I use echo and grep
? 我是否使用echo和grep
? .net
if echo "$string" | grep 'foo'; then echo "It's there!" fi
That looks a bit clumsy. 看起来有点笨拙。 code