Grep在OpenBSD中对Linux的表现不同.无法让命令工作

lin*_*fun 4 regex linux grep openbsd

所以这个命令基本上是安全地连接到一个Web域来获取我的外部IP地址,这在Linux Debian系统上完美运行,但它在我的OpenBSD系统上无法正常工作.Curl命令工作正常,但是Grep命令有些问题,因为它只是没有抓住卷曲管道到它的IP.

是 - 是不是可以使用OpenBSD?我无法用手册页告诉我..

USERAGENT="Mozilla/4.0"
WEB_LOCATION="https://duckduckgo.com/?q=whats+my+ip"

curl -s --retry 3 --max-time 5 -tlsv1.2 --user-agent $USERAGENT $WEB_LOCATION | grep -Eo '\<[[:digit:]]{1,3}(\.[[:digit:]]{1,3}){3}\>'
Run Code Online (Sandbox Code Playgroud)

*******RESOLVED(Kinda)********

我通过某种原因计算出这种特殊模式:

grep -Eo '\<[[:digit:]]{1,3}(\.[[:digit:]]{1,3}){3}\>'
Run Code Online (Sandbox Code Playgroud)

没有在OpenBSD上工作,但这个长版本确实如此......

grep -Eo '[[:digit:]]{1,3}\.[[:digit:]]{1,3}\.[[:digit:]]{1,3}\.[[:digit:]]{1,3}'
Run Code Online (Sandbox Code Playgroud)

为什么会出现这种情况非常令人困惑,因为第一个搜索模式在我使用的所有Debian Linux版本上都能正常工作!

ci_*_*ci_ 7

问题是,在你的正则表达式的字边界模式,这是[[:<:]][[:>:]]OpenBSD中,但\<\>分别在Debian的(也可能是其他Linux发行版).

grep -Eo '[[:<:]][[:digit:]]{1,3}(\.[[:digit:]]{1,3}){3}[[:>:]]'
Run Code Online (Sandbox Code Playgroud)

应该管用.

阅读手册页了解详细信息.