Why grep ‘.*[s]’ Works and grep .*[s] Doesn’t

command linegrepquotingshell

Comparing

grep '.*[s]' file

with

grep .*[s] file

Why do you need quotation marks to let this work properly? In the second case, grep seems trying to inspect every file with a period.

Best Answer

Quotes (either single or double) around an argument inhibit glob expansion.

Your first example passes a Regular Expression as an argument to grep. Your second example contains a glob pattern which the shell itself expands, passing filenames that fit that pattern as arguments to grep.

Related Question