The shell interprets [a-z]
first if it is not quoted, before ever passing it to grep
.
[a-z]
is expanded to all the filenames found in the working directory that consist of exactly one letter between a and z.
I'll bet if you do a ls
you will find a file (in the current directory) with the name t
, or some other letter that is only present in "insert something" but not in the other strings (lines of text). If in your working directory you have several files, but exactly one has a one-letter name like t
, then your first command is expanded to grep t test
.
So - yes, you must quote your regular expression, so it is passed as is to grep
and it is not processed by the shell.