Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 7 Dec 2017 06:57:00 +0100
From:      Michael Schuster <michaelsprivate@gmail.com>
To:        Vladimir Botka <vbotka@gmail.com>
Cc:        Yuri Pankov <yuripv@gmx.com>, RW <rwmaillists@googlemail.com>,  freeBSD Mailing List <freebsd-questions@freebsd.org>
Subject:   Re: grep problem
Message-ID:  <CADqw_gK2b8t4yC5c4GD3ivWaT0wsRTHMuQ9P_5b0jZHVNmcVjA@mail.gmail.com>
In-Reply-To: <20171207024717.15bf2287@planb.netng.org>
References:  <20171207005542.43a7f55f@gumby.homeunix.com> <8277e864-c52a-09a4-dca9-58f83469f5fc@gmx.com> <20171207024717.15bf2287@planb.netng.org>

next in thread | previous in thread | raw e-mail | index | archive | help
On Thu, Dec 7, 2017 at 2:49 AM, Vladimir Botka <vbotka@gmail.com> wrote:

> > > $ 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
>
> FWIW. Still the question remains what makes escaped -b a pattern. It'd
> be necessary to learn about getopt_long which is used to parse the
> arguments to understand it, I think.
>

I think it's much more straight-forward:

single quotes cause \-b to be passed to grep, grep sees the "\" as escape
and therefore *doesn't* read '-' as introducing an option, ergo -b must be
a pattern to match.

cheers
Michael
-- 
Michael Schuster
http://recursiveramblings.wordpress.com/
recursion, n: see 'recursion'



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?CADqw_gK2b8t4yC5c4GD3ivWaT0wsRTHMuQ9P_5b0jZHVNmcVjA>