我有两个脚本,我想在 Linux 机器和 MacOS 机器上运行。但是egrep
命令的不同行为使这些脚本生成不同的输出。
特别是,当我egrep
在 Linux (Ubuntu) 上使用时会发生这种情况:
$ echo ".test" | egrep "[a-zA-Z0-9]*"
.test
$ echo ".test" | egrep -o "[a-zA-Z0-9]*"
test
$
这就是我egrep
在 MacOS 上使用时发生的情况
$ echo ".test" | egrep "[a-zA-Z0-9]*"
.test
$ echo ".test" | egrep -o "[a-zA-Z0-9]*"
$
第一个行为是我所期望的,第二个(空输出)是出乎意料的。也许这是在 MacOS 下执行egrep
with选项的错误?-o
或者,如果第二种行为也是正确的,您是否知道在第二种情况下获得相同行为的方法?
我试图查看man
这两个命令的相应页面,这是从 Linux 手册页中提取的:
-o, --only-matching
Print only the matched (non-empty) parts of a matching line, with each
such part on a separate output line.
这是从 MacOS 的手册页中提取的:
-o, --only-matching
Prints only the matching part of the lines.
虽然描述看起来有点不同,但两个选项的含义似乎是一样的,那么为什么egrep -o
在 MacOS 中表现不同呢?我没有考虑这个命令的任何微妙方面吗?