Xiaohan Peng
Xiaohan Peng

Reputation: 51

bash: Variable including wildcards not interpreted in grep

Within bash, I'm trying to using grep to search input string in multiple files. As I have different patterns matching I use a variable which is filename with wildcards.

I found it didn't interpret the wildcards because it interpreted just as question mark.

pattern="Report????.log"
grep -ciF $input "$pattern"

If I just write

grep -ciF $input Report????.log

this definitely works.

So is there a way to solve this if I still want to use variable with wildcards?

Upvotes: 0

Views: 119

Answers (1)

j23
j23

Reputation: 3530

Remove the quotes in $pattern and it will work.

pattern="Report????.log"
grep -ciF $input $pattern

Upvotes: 2

Related Questions