Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 7 Dec 2017 04:20:13 +0300
From:      Yuri Pankov <yuripv@gmx.com>
To:        RW <rwmaillists@googlemail.com>, freebsd-questions@freebsd.org
Subject:   Re: grep problem
Message-ID:  <8277e864-c52a-09a4-dca9-58f83469f5fc@gmx.com>
In-Reply-To: <20171207005542.43a7f55f@gumby.homeunix.com>
References:  <20171207005542.43a7f55f@gumby.homeunix.com>

next in thread | previous in thread | raw e-mail | index | archive | help
On Thu, Dec  7, 2017 at 00: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

Looks like it's treated as option -b even inside the single quotes, you 
could use '--' to mark the end of options, i.e.:

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



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?8277e864-c52a-09a4-dca9-58f83469f5fc>