Too much arguments with grep at if

*爱你&永不变心* 提交于 2020-01-16 05:01:07

问题


I was trying to look for $allowtunnel string at my file.

Based on: How to test if string exists in file with Bash shell?

So now I've the following at my script:

allowtunnel="PermitTunnel"
if [ grep -Fxq $allowtunnel /etc/ssh/sshd_config ]; then

Since at execution time it says "too much arguments", I was looking and found this:

Bash script - too many arguments

So I change it to:

if [[ grep -Fxq $allowtunnel /etc/ssh/sshd_config ]]; then

But now, It delivers me the next one:

./script_install.sh: línea 242: se esperaba un operador binario condicional
./script_install.sh: línea 242: error sintáctico cerca de `-Fxq`
./script_install.sh: línea 242: `    if [[ grep -Fxq $allowtunnel /etc/ssh/sshd_config ]]; then`

Translated would be:

./script_install.sh: line 242: binary conditional operator was expected
./script_install.sh: line 242: syntax error near of `-Fxq`
./script_install.sh: line 242: `    if [[ grep -Fxq $allowtunnel /etc/ssh/sshd_config ]]; then`

So as I understand, It doesn't let me use a second [] because it expects another operator. That leaves me without knowing what to do.

I've also seen this one: Too many arguments error in bash , but since I'm not comparing something but waiting for the result of grep I get anything useful from this one.

Thanks for reading


回答1:


Since grep returns an exit status depending if the record is found or not, you could write your if statement like:

if grep .....; then


来源:https://stackoverflow.com/questions/27667340/too-much-arguments-with-grep-at-if

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!