Re: [Hampshire] Escape characters with man | grep

Top Page

Reply to this message
Author: Adrian Bridgett
Date:  
To: Hampshire LUG Discussion List
Subject: Re: [Hampshire] Escape characters with man | grep
On Mon, May 10, 2010 at 10:35:20 +0100 (+0100), Owain Clarke wrote:
> I'm sure this is an easy one for you:-
>
> If I want to read a line from a man page with a character which needs
> escaping, how do I do it? For example, to read the -r option of rsync:-
> man rsync | grep -r
> produces no output, presumably because the - needs escaping.


It doesn't need escaping per-se (it's not a protected character - e.g.
"grep '-r'" won't work either. It's being interpreted as "please work
recursively".

As kish/krisk/Esse (sorry, couldn't figure out which was your name!!)
suggests, using a backslash works as it then passes \-r into grep.

However the easiest trick is that most programs will interpret "--" as
"end of all options". So you can use "grep -- -r".

Adrian
--
bitcube.co.uk - Expert Linux infrastructure consultancy
Puppet, Debian, Red Hat, Ubuntu, CentOS