Subject: Pattern Beginning With Dash Throws Error

From: [email-masked]
Date: Sat, 18 Jun 2022 22:05:07 +0200 (CEST)

Hello,

I just encountered a problem where when the search pattern starts with a dash, grep interprets it as an argument parameter. It does not matter in what kind of quotes the pattern is wrapped. See examples below.
$ echo "- break -" | grep "- break -"
grep: invalid option -- ' '
Usage: grep [OPTION]... PATTERNS [FILE]...
Try 'grep --help' for more information.
$ echo "- break -" | grep '- break -'
grep: invalid option -- ' '
Usage: grep [OPTION]... PATTERNS [FILE]...
Try 'grep --help' for more information.
$ echo "- break -" | grep '^- break -'
- break -
$ echo "- break -" | grep "^- break -"
- break -
$ echo "- break -" | grep "-s break -"
grep: invalid option -- ' '
Usage: grep [OPTION]... PATTERNS [FILE]...
Try 'grep --help' for more information.

grep Version: grep (GNU grep) 3.7

Sincerely,
Gazi