[20180417]奇怪的grep过滤问题.txt
--//链接:http://blog.itpub.net/267265/viewspace-2144230/
--//上个星期的测试,没时间探究,今天继续.
--//以前做的测试为了避免输出的一些干扰,我喜欢加括号,这样查询内容是一样的,但是执行grep那行不输出.
--//但是我今天遇到一个问题,很奇怪做一个记录.
$ ps -ef | grep /u01/app/11.2.0.4/grid/bin/tnslsn[r]
grid 45935 1 0 Jan25 ? 02:09:55 /u01/app/11.2.0.4/grid/bin/tnslsnr LISTENER_SCAN2 -inherit
grid 46223 1 0 Jan25 ? 02:22:50 /u01/app/11.2.0.4/grid/bin/tnslsnr LISTENER_SCAN3 -inherit
grid 46974 1 0 Jan25 ? 11:03:24 /u01/app/11.2.0.4/grid/bin/tnslsnr LISTENER -inherit
grid 77598 77309 0 09:26 pts/4 00:00:00 grep /u01/app/11.2.0.4/grid/bin/tnslsnr
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
--//很奇怪执行grep也输出.而如果写成:
$ ps -ef | grep tnslsn[r]
grid 45935 1 0 Jan25 ? 02:09:55 /u01/app/11.2.0.4/grid/bin/tnslsnr LISTENER_SCAN2 -inherit
grid 46223 1 0 Jan25 ? 02:22:51 /u01/app/11.2.0.4/grid/bin/tnslsnr LISTENER_SCAN3 -inherit
grid 46974 1 0 Jan25 ? 11:03:24 /u01/app/11.2.0.4/grid/bin/tnslsnr LISTENER -inherit
$ ps -ef | grep /tnslsn[r]
grid 45935 1 0 Jan25 ? 02:09:55 /u01/app/11.2.0.4/grid/bin/tnslsnr LISTENER_SCAN2 -inherit
grid 46223 1 0 Jan25 ? 02:22:51 /u01/app/11.2.0.4/grid/bin/tnslsnr LISTENER_SCAN3 -inherit
grid 46974 1 0 Jan25 ? 11:03:24 /u01/app/11.2.0.4/grid/bin/tnslsnr LISTENER -inherit
--//执行grep命令那行没有输出,为什么.....grep环境变量定义如下:
$ env | grep GREP
GREP_COLOR=01;32
GREP_OPTIONS=--color=auto
--//而执行如下:
$ ps -ef | grep /[u]01/app/11.2.0.4/grid/bin/tnslsnr
grid 45935 1 0 Jan25 ? 02:09:55 /u01/app/11.2.0.4/grid/bin/tnslsnr LISTENER_SCAN2 -inherit
grid 46223 1 0 Jan25 ? 02:22:51 /u01/app/11.2.0.4/grid/bin/tnslsnr LISTENER_SCAN3 -inherit
grid 46974 1 0 Jan25 ? 11:03:24 /u01/app/11.2.0.4/grid/bin/tnslsnr LISTENER -inherit
grid 79549 77309 0 09:27 pts/4 00:00:00 grep /u01/app/11.2.0.4/grid/bin/tnslsnr
$ ps -ef | grep [u]01/app/11.2.0.4/grid/bin/tnslsnr
grid 45935 1 0 Jan25 ? 02:09:55 /u01/app/11.2.0.4/grid/bin/tnslsnr LISTENER_SCAN2 -inherit
grid 46223 1 0 Jan25 ? 02:22:51 /u01/app/11.2.0.4/grid/bin/tnslsnr LISTENER_SCAN3 -inherit
grid 46974 1 0 Jan25 ? 11:03:24 /u01/app/11.2.0.4/grid/bin/tnslsnr LISTENER -inherit
$ ps -ef | grep [u]01/app/11.2.0.4/grid/bin/tnslsn[r]
grid 45935 1 0 Jan25 ? 02:09:55 /u01/app/11.2.0.4/grid/bin/tnslsnr LISTENER_SCAN2 -inherit
grid 46223 1 0 Jan25 ? 02:22:52 /u01/app/11.2.0.4/grid/bin/tnslsnr LISTENER_SCAN3 -inherit
grid 46974 1 0 Jan25 ? 11:03:26 /u01/app/11.2.0.4/grid/bin/tnslsnr LISTENER -inherit
--//blog没有颜色显示,实际上字串/u01/app/11.2.0.4/grid/bin/tnslsnr显示为绿色.
--//也就是grep /[u]01/app/11.2.0.4/grid/bin/tnslsnr实际上执行的是grep /u01/app/11.2.0.4/grid/bin/tnslsnr
--//why?
--//如果写成这样又ok:
$ ps -ef | grep /u01/app/11.2.0.4/grid/bin[/]tnslsnr
grid 45935 1 0 Jan25 ? 02:09:55 /u01/app/11.2.0.4/grid/bin/tnslsnr LISTENER_SCAN2 -inherit
grid 46223 1 0 Jan25 ? 02:22:51 /u01/app/11.2.0.4/grid/bin/tnslsnr LISTENER_SCAN3 -inherit
grid 46974 1 0 Jan25 ? 11:03:25 /u01/app/11.2.0.4/grid/bin/tnslsnr LISTENER -inherit
--//感觉视乎和斜线有关,视乎与过滤是否是1个词有关.不知道为什么?放弃那位知道.