Why are these two commands equivalent (or so it seems based on the results I get back)? I figured the first command wouldn't work because the * would be treated as the glob operator but instead it got passed into grep just fine and interpreted as a regex pattern.

git diff master | grep \\+.*TODO
git diff master | grep \\+.\*TODO

A filename glob will only be expanded if there's a matching file in the current directory - otherwise (barring any nullglob or failglob shell options) it will be passed as-is. So:

$ echo \\+.*TODO
$ printf '+foo\n+TODO\n+bar' | grep \\+.*TODO


$ touch '\+.abcTODO'
$ echo \\+.*TODO
$ printf '+foo\n+TODO\n+bar' | grep \\+.*TODO
$ printf '+foo\n+TODO\n+bar' | grep \\+.\*TODO
  • Oh wow I never noticed that behavior. Thanks so much for explaining! – 11th Hour Worker Aug 17 '17 at 18:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.