bash: 包含通配符的变量未在 grep 中解释

bash: Variable including wildcards not interpreted in grep

在 bash 中,我正在尝试使用 grep 在多个文件中搜索输入字符串。因为我有不同的模式匹配,所以我使用一个变量,它是带有通配符的文件名。

我发现它不解释通配符,因为它只解释为问号。

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

如果我只写

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

这绝对有效。

如果我仍然想使用带通配符的变量,有没有办法解决这个问题?

删除 $pattern 中的引号,它将起作用。

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