I am using a simple text file to test the *
meta-character through grep.
The text file is as below:
1
11
111
1111
11111
111111
d
da
daa
daaa
b
bc
bcc
bccc
Now when I search digit 1 using grep like this:
grep 1* regex.txt
output is
1
11
111
1111
11111
111111
d
da
daa
daaa
b
bc
bcc
bccc
Even in the case of character 'd' the result is same with highlighted 'd' in red BUT in the case of character 'a' & 'b' there is no output for the following search command:
grep a* regex.txt
grep b* regex.txt
AND the below commands give expected output
grep "a*" regex.txt
grep "b*" regex.txt
Why so? Why is bash
partial towards the character 'd' and not to 'a' & 'b'
*
is expanded by shell path. If there is no output fora*
tryecho a*
and you should see files with names started witha
(sameb
)*
means zero-or-more of the last character/sub-expression. It does not mean "followed by anything" as it does in a shell wildcard.