I am playing around with piping and grep tonight. I know that grep uses regex and that * means 0 or more occurrences of the preceding character. So the way I understand it is that if I do the following command, the entire directory should be listed... but nothing is listed. All that happens is the command line resets:
[root@LinuxAcademy etc]# ls /etc | sort | grep d*
[root@LinuxAcademy etc]#
However, if I do the command again and replace d with p, the entire directory is listed just as I would expect:
[root@LinuxAcademy ~]# ls /etc | sort | grep p*
ConsoleKit
DIR_COLORS
DIR_COLORS.256color
DIR_COLORS.lightbgcolor
NetworkManager
X11
...........<<rest of listing not pasted in>>
Even though no error was given when i used the grep d*, I redirected stderr to a file just to check and nothing was printed.
I then thought that grep may be interpreting the 'd' in 'grep d*' to be an option or command... but that doesn't seem to be the case either.
Can anyone help me understand what is going on and why when i use the command with
grep d*
nothing is listed?
What you said happens with p* is exactly what I expected. I also expect it when I use d*.... but nothing happens and that's the trivia here that I have.
I am not trying with any specific purpose but to produce unexpected results and better understand the processing... which you did help me do so thank you.
So why doesn't grep d* list entire directory just like grep p*. That's what I don't get.
– Brad Harris Aug 09 '14 at 02:10etc
in the first command, presumably/etc
, so at least the directory whose name the glob was expanded into should have been matched. @BradHarris try this: After typing the command, pressTab
- bash will try to autocomplete thed*
glob. This will let you see whatd*
actually expands into before grep gets a hold of it. – muru Aug 09 '14 at 02:17