grep problem
Michael Schuster
michaelsprivate at gmail.com
Thu Dec 7 05:57:21 UTC 2017
On Thu, Dec 7, 2017 at 2:49 AM, Vladimir Botka <vbotka at 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'
More information about the freebsd-questions
mailing list