我需要询问您有关grep
在 Debian 中的 Bash 脚本中使用命令的问题。
我有包含以下几行的示例文件:
/fruit-/apple.txt
/fruit-/banana.txt
/fruit-/samples
/vegetables-/carrot.txt
/vegetables-/garlic.txt
Run Code Online (Sandbox Code Playgroud)
我想选择包含 word 的所有行fruit-
。
我可以调用命令:
grep -w "fruit-" file.txt
Run Code Online (Sandbox Code Playgroud)
输出将是:
/fruit-/apple.txt
/fruit-/banana.txt
/fruit-/samples
Run Code Online (Sandbox Code Playgroud)
但是当我使用命令时:
grep -w "fruit" file.txt
Run Code Online (Sandbox Code Playgroud)
我也得到与上面相同的输出。但这是错误的。输出应该是 0。因为我没有输入-
模式。
为什么不正确grep
对待-
呢?