0

In bash,

grep -r --exclude={*.c,} 'HELLO'  // exclude c files

grep -r --include={*.c,} 'HELLO'  // just same with grep -r 'HELLO'

What's the problem?

HyunYoung Go
  • 103
  • 9

1 Answers1

2

You are using curly braces incorrectly. The correct syntax would look like

grep -r --include='*.c' 'HELLO' .

(Notice also the addition of the missing file name argument . at the end.)

You can see what's going wrong by putting an echo in front and examining what the shell expands the braces to.

$ echo grep -r --exclude={*.c,} 'HELLO'
grep -r --exclude=*.c --exclude= HELLO
tripleee
  • 175,061
  • 34
  • 275
  • 318
  • `GNU grep` will search current directory with `-r` active when filename argument isn't given – Sundeep Mar 04 '21 at 14:07
  • Yeah, there's a lot of GNU conveniences which are not portable. I try to avoid them in answers when I can, or point out when something I use isn't portable, even when the question mentions a specific platform. – tripleee Mar 04 '21 at 14:16
  • [The place where you apparently pioked up the braces](https://stackoverflow.com/a/221929/874188) has been updated to no longer recommend them. – tripleee Mar 04 '21 at 19:34