1

I'm checking to see if a specific string exists on any line in a specific file as shown below:

if grep -Fxq "-a always,exit -F arch=b32 -S chmod -F auid -k perm_mod" /etc/audit/audit.rules; then
    echo "text found."
fi

However, I get a message that grep is being passed an invalid option ' ' (a space character). I also tried saving the string to a variable and then using grep on the variable. It modifies the error to say that -S is an invalid option.

I think that somehow my entire string is not being interpreted as input to grep, with part of the string being interpreted as options.

Lee Exothermix
  • 316
  • 2
  • 3
  • 14

1 Answers1

1

Separate your search pattern with --:

grep -Fxq -- "-a always,exit -F arch=b32 -S chmod -F auid -k perm_mod" \
/etc/audit/audit.rules && echo "text found."

You're getting this error because your search pattern starts with -a which is interpreted as an option to grep.

anubhava
  • 761,203
  • 64
  • 569
  • 643