0

I'm trying to understand the difference of single and double quotes in these particular situations:

egrep '^Za(za)+!$' *

returns Zaza! and Zazazazaza! (Which is what I want)

egrep "^Za(za)+!$" *

returns the ones I mentioned above but also Zaaazazaaaa!, Zaza, Zazaza!Zazaza!, Za!

From my understanding, double quotes take the meanings of the symbols like + into account, so why would the double quotes not work?

cosmicluna
  • 539
  • 1
  • 5
  • 16
  • If you don't use _history expansion_ and don't want surprises like this, turn it off with `set +H`. To keep it off automaticly, you may want to place this command in `~/.bashrc`. – John1024 Sep 17 '17 at 20:38

1 Answers1

2

!$ is a history expansion that selects the last word from the previous command (so the result actually depends on that other command!). Those are processed inside double quotes but not inside single quotes.

Davis Herring
  • 36,443
  • 4
  • 48
  • 76