strA="long string"
strB="string"
result=$(echo $strA | grep "${strB}")
if [[ "$result" != "" ]]
then
echo "包含"
else
echo "不包含"
fi
strB="string"
result=$(echo $strA | grep "${strB}")
if [[ "$result" != "" ]]
then
echo "包含"
else
echo "不包含"
fi
本文介绍了一个简单的Shell脚本示例,用于演示如何检查一个字符串是否包含另一个字符串。通过使用`grep`命令,脚本能够判断指定的子字符串是否存在於父字符串中,并据此输出相应的结果。
819

被折叠的 条评论
为什么被折叠?



