【问题标题】:ksh IP address patternksh IP 地址模式
【发布时间】:2013-11-08 01:48:48
【问题描述】:

尝试匹配 $1 以查看它是否是 ksh 中的 IP 地址。

if [ $1 = "^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$" ]

似乎没有识别以下内容

ksh -x samp.sh 192.168.128.10

【问题讨论】:

标签: regex shell ksh


【解决方案1】:

试试

"[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}"

仅限 Ksh has a subset of regex

【讨论】:

  • 谢谢 不顺利。没有时间,而是在 bash 中做到了。 :(
【解决方案2】:

我在 KSH93 中使用了以下正则表达式评估,它对我有用。

if [[ $1 == {1,3}(\d).{1,3}(\d).{1,3}(\d).{1,3}(\d) ]]
then
# regex expression evaluated to true
<< perform some action here .... >>
else
# regex expression evaluated to false
<< perform some action here .... >>
fi

【讨论】:

    猜你喜欢
    • 2021-04-27
    • 2019-08-25
    • 2012-07-30
    • 2012-05-17
    • 1970-01-01
    • 2020-02-13
    • 2019-11-01
    • 2012-03-07
    • 1970-01-01
    相关资源
    最近更新 更多