ksh脚本中的模式匹配 [英] Pattern matching in ksh script

查看:63
本文介绍了ksh脚本中的模式匹配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在

a=44&search=My World

在这里我要进行模式匹配

here I want to do a pattern matching like

if [ $a =~ "search" ] ;
then
   value=1
else
   value=0

fi

但是它不适用于KSH脚本.

But it is not working in KSH script.

推荐答案

您需要[[用于ksh正则表达式,而不是Bourne shell [.尽管在这种情况下,似乎几乎不值得使用RE.

You need [[ for ksh regular expressions, not the Bourne shell [. Although in this case it hardly seems worth using an RE.

所以:

if [[ $a =~ "search" ]]
then 
    value=1 
else 
    value=0
fi

这篇关于ksh脚本中的模式匹配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆