#!/bin/bash
#my=`grep -c 'print' views_test.py`
#echo $my
#echo $my
strA="helloworld"
strB="lowp"
strC="help"
strD="rldp"
if [[ $strA =~ $strB || $strA =~ $strC || $strA =~ $strD ]];
then
echo "包含"
else
echo "不包含"
fi
注:执行shell脚本时,若一直格式错误,可cat进行查看脚本文件,看是否正常。
cat -A filename.txt
本文介绍了一段Shell脚本代码,演示了如何使用正则表达式在字符串中查找子串。通过具体示例,展示了当字符串包含特定子串时,如何在终端输出相应的结果。此外,还提供了一个实用技巧,即使用cat命令检查脚本格式,以确保脚本正确无误。
1万+





