1

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

Community
  • 1
  • 1
Btc Sources
  • 1,912
  • 2
  • 30
  • 58

1 Answers1

3

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

if grep .....; then
user000001
  • 32,226
  • 12
  • 81
  • 108