Search code examples
bashshellfilegrepcomments

How can I "grep" matching a "comment" string?


I've a README.md file with this text (notice the comment):

[//]: # (Template README)

This is my file bla bla bla

Doing this:

readme_file=./README.md

if grep -q "[//]: # (Template README)" "$readme_file"; then
  echo "match"
fi

Doesn't match the string.

Why? How can I match it?


Solution

  • Use grep -F for that.

    grep -F "[//]: # (Template README)" README.md
    

    -F interpret pattern as a set of fixed strings (i.e. force grep to behave as fgrep).