为什么我的带有grep的Bash脚本不起作用?

为什么我的带有grep的Bash脚本不起作用?,bash,if-statement,grep,Bash,If Statement,Grep,我试图理解为什么这个非常简单的脚本不起作用: echo "SomeText" > test if [[ "grep 'FindMe' ./test" ]] ; then echo Why is this line written to screen? fi 我试过: “grep'FindMe./test” $(grep'FindMe./test) `grep'FindMe./test` 还有很多grep选项 我尝试了[]和[[]]和{}以及任何组合。事实上,要检查退出状态,请不要使用

我试图理解为什么这个非常简单的脚本不起作用:

echo "SomeText" > test
if [[ "grep 'FindMe' ./test" ]] ; then
  echo Why is this line written to screen?
fi
我试过:

“grep'FindMe./test”

$(grep'FindMe./test)

`grep'FindMe./test`

还有很多grep选项


我尝试了
[]
[[]]
{}
以及任何组合。

事实上,要检查退出状态,请不要使用括号和引号:

if grep 'FindMe' ./test ; then
在这样的情况下,使用
grep-q
是很常见的,因为我们不希望脚本的输出被随机匹配弄得乱七八糟