Reputation: 425
I was surprised to find out that the single quote version works with regular expressions just the same. The only real difference I see now is that double quotes expand variables inside the regex pattern. Is there anything else I am missing?
Upvotes: 15
Views: 9246
Reputation: 113834
The difference between single quotes and double quotes is a shell issue, not a grep
issue. It is the shell that decides to do or not to do variable expansion before passing the arguments to grep
. Because the last step in shell processing of arguments is quote removal, grep
never even sees the quotes.
Variable expansion is not the only difference between single and double quotes. The shell also does command substitution and arithmetic expansion inside double quotes. For example:
$ echo "$(date) and 2+2=$((2+2))"
Tue Aug 5 18:52:39 PDT 2014 and 2+2=4
$ echo '$(date) and 2+2=$((2+2))'
$(date) and 2+2=$((2+2))
Upvotes: 24