> ps -ef | grep cron
root 1052 1 0 04:35 ? 00:00:00 cron
test 4071 4053 0 10:15 pts/0 00:00:00 grep --color=auto cron
> ps -ef | grep cr[o]n
root 1052 1 0 04:35 ? 00:00:00 cron
为什么当搜索词相同时这两个命令返回不同的结果?
最佳答案
因为在第二种情况下,实际运行的进程是(虽然在应用 grep 过滤器后您看不到第二种情况):
root 1052 1 0 04:35 ? 00:00:00 cron
test 4071 4053 0 10:15 pts/0 00:00:00 grep --color=auto cr[o]n
并且 cr[o]n
与 cr[o]n
不匹配,因为 [o]
指定了字符列表 o
,而真正的字符串在 o
周围还包含 [
和 ]
。
关于regex - 为什么在使用正则表达式时 grep 会返回不同的结果?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35045139/