grep problem

RW rwmaillists at googlemail.com
Thu Dec 7 00:55:47 UTC 2017


Can anyone explain why '-' needs escaping in the following. What
special meaning does it have outside of []? 

$ echo 'a-b' | grep  'a-b'
a-b

$ echo 'a-b' | grep  '-b'
Usage: grep [OPTION]... PATTERN [FILE]...
Try `grep --help' for more information.

$ echo 'a-b' | grep  '\-b'
a-b



More information about the freebsd-questions mailing list