参见英文答案 >
Grep for literal strings5个
有没有办法让grep匹配一个精确的字符串,而不是将其解析为正则表达式?或者是否有一些工具可以正确地为grep转义字符串?
有没有办法让grep匹配一个精确的字符串,而不是将其解析为正则表达式?或者是否有一些工具可以正确地为grep转义字符串?
$version=10.4 $echo "10.4" | grep $version 10.4 $echo "1034" | grep $version # shouldn't match 1034
使用grep -F或fgrep.
原文链接:https://www.f2er.com/bash/384389.html$echo "1034" | grep -F $version # shouldn't match $echo "10.4" | grep -F $version 10.4
见手册页:
06001
我一直在寻找术语“文字匹配”或“固定字符串”.
(另见Using grep with a complex string和How can grep interpret literally a string that contains an asterisk and is fed to grep through a variable?)