HyunYoung Go
HyunYoung Go

Reputation: 103

grep -r --include not works but --exclude works

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?

Upvotes: 0

Views: 319

Answers (1)

tripleee
tripleee

Reputation: 189648

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

Upvotes: 2

Related Questions