linux - grep 不作为正则表达式

我需要搜索一个 PHP 变量 $someVar。但是,Grep 认为我正在尝试运行正则表达式并提示:

$ grep -ir "Something Here" * | grep $someVar
Usage: grep [OPTION]... PATTERN [FILE]...
Try `grep --help' for more information.
$ grep -ir "Something Here" * | grep "$someVar"
<<Here it returns all rows with "someVar", not only those with "$someVar">>

我没有看到告诉 grep not 将字符串解释为正则表达式的选项,而是将 $ 包含为另一个字符串字符。

最佳答案

使用 fgrep(已弃用)、grep -Fgrep --fixed-strings,使其将模式视为列表固定字符串,而不是正则表达式。

作为引用,文档提到(摘录):

-F --fixed-strings Interpret the pattern as a list of fixed strings (instead of regular expressions), separated by newlines, any of which is to be matched. (-F is specified by POSIX.)

fgrep is the same as grep -F. Direct invocation as fgrep is deprecated, but is provided to allow historical applications that rely on them to run unmodified.

如需完整引用,请查看: https://www.gnu.org/savannah-checkouts/gnu/grep/manual/grep.html

https://stackoverflow.com/questions/9416390/

相关文章:

linux - WGET 是否超时?

python - 在python中调用带有参数列表的函数

python - 我如何告诉 matplotlib 我完成了一个情节?

linux - Bash 中的多线程

linux - tar:添加当前目录中的所有文件和目录,包括 .svn 等

python - 如何中止 Python 脚本的执行?

python - 如何从生成器构建 numpy 数组?

python - 如何使用 Python 登录网页并检索 cookie 以供以后使用?

python - 删除字符串的第一个字符

linux - 如何在 Linux 上的某个时间运行脚本?