grep problem

Ken Moffat zarniwhoop at ntlworld.com
Thu Dec 7 01:09:14 UTC 2017


On Thu, Dec 07, 2017 at 12:55:42AM +0000, RW via freebsd-questions wrote:
> 
> 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
> 
In gnu grep, '-' indicates it should read from STDIN, I assume that
FreeBSD's grep is the same.

ĸen
-- 
Truth, in front of her huge walk-in wardrobe, selected black leather
boots with stiletto heels for such a barefaced truth.
                                     - Unseen Academicals


More information about the freebsd-questions mailing list