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