0

I want to read about one option in man page of gcc. So i did man gcc | grep -- '^-c'. The error was troff - cant break line, because I have terminal on the half on my screen. But I fixed that with declaration of MANWIDTH=1000 man gcc | grep -- '^-c' (thanks to: Why is this "can't break line" warning from grep of gcc man page?. But unfortunately it wont find it that option. Without the begginig pattern (that is only -c : in full : MANWIDTH=1000 man gcc | grep -- '-c', It will find all the occurrence of -c, which is quit a lot, but particularly the option I am looking for will be messed up with useless searches. So why does not the grep uses ^ and $ as beginning and end of the line? Or does it have something to do with the size of my terminal window (that is, shorten by width) = the anchor of lines? And how can I then search with grep by beginning of lines without fullscreening the terminal?

PS: I do not know why, when I declare the MANWIDTH var, it won't apply with man command immediately, despite it's value. That is, If i declare it first, and then try to man something (eventually pipe it to grep for lines search), The error arise again : troff: warning: can't break line

As this:

MANWIDTH=1000; echo $MANWIDTH #output 1000 man gcc | grep -- '^-c' troff: <standard input>:10635: warning [p 97, 19.0i]: can't break line 
0

1 Answer 1

0

The -c is not at the beginning of the line because it is not at the left margin. You could use the pattern ^\s*-c which allows zero or more whitespace characters between the beginning of the line and the -c.

But if you want to read the documentation for the -c command, you're better off using the info command, at least in this case:

info gcc --index-search=c 

Note: For this to work, you need to have installed the gcc info pages. On Debian/Ubuntu systems, for example, you'll want to sudo apt-install gcc-doc.

Note: the gcc info file authors chose not to put leading hyphens in index entries for most options. But most info files follow the convention of indexing with both with and with the dash (as gcc does with a few of the -f options). Although info will try to find the most relevant index match, info index searches are substring matches of literal strings (i.e. no regex operators) and sometimes you'll prefer to search with the dash:

info grep --index-search=-E 

or to use the -all option to provide a listing of all matching index entries:

info grep --all --index-search=E 

For utilities with fewer options than gcc, you might just go directly to the options listing with the -O option.

info grep -O 

Finally, the answer to your PS:

Use export MANWIDTH=1000 if you want MANWIDTH to be an environment variable visible to all subprocesses.

Sign up to request clarification or add additional context in comments.

8 Comments

But when I do info gcc --index-search=c, then no index entries found for 'c', why?
@Herdsman: Probably because you never installed the gcc info file. Does info gcc just show you the same output as man gcc? I'll add a note.
@herdsman: sudo apt-get install gcc-doc if you're on Ubuntu/Debian
@Herdsman: no, it can be annoying to figure out what you need. In general, if you're installing some package x, you should also install x-doc (if it exists). But your automatically installed packages might or might not include info files, and it's not always obvious which doc package to install. You can certainly try x-doc. It can't hurt.
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.