Match with grep when pattern contains hyphen "-"

Place -- before your pattern:

echo "$a"  | grep -Fxc -- "$b"

-- specifies end of command options for many commands/shell built-ins, after which the remaining arguments are treated as positional arguments.


Besides of @sebasth's great answer, you could tell that PATTERN with grep's -e option to use PATTERN as a pattern (here using the <<< zsh here-string operator instead of echo; see also printf '%s\n' "$a" for portability).

grep -Fxc -e "$b" <<<"$a"

Or all beside of other options.

grep -Fxce "$b" <<<"$a"

Since your goal is byte-to-byte string equality comparison use the [ command instead.

if [ "$a" = "$b" ]

Or if $a contains $b, using the [[...]] ksh construct:

if [[ $a == *"$b"* ]]

Or more portably in all Bourne-like shells:

case $a in
  *"$b"*) ...
esac