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?

1 Answer 1

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 
Sign up to request clarification or add additional context in comments.

3 Comments

GNU grep will search current directory with -r active when filename argument isn't given
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.
The place where you apparently pioked up the braces has been updated to no longer recommend them.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.