1、if [[ "$file" =~ 'start' ]]
2、或if [[ "$file" =~ "start" ]]
例子:
#!/usr/bin/ksh
file="10start11.s"
if [[ "$file" =~ "start" ]]
then
echo "success"
else
echo "failed"
fi
只有bash才支持[[
ksh在test中应该不支持正则,用awk grep sed等工具实现吧
flag=`echo $file |awk '/start/'`
if [ "$flag" = "" ];then
echo "success"
else
echo "failed"
fi
阅读(13489) | 评论(1) | 转发(0) |