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
Herdsman
  • 799
  • 1
  • 7
  • 24

1 Answers1

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.

rici
  • 234,347
  • 28
  • 237
  • 341
  • But when I do `info gcc --index-search=c`, then `no index entries found for 'c'`, why? – Herdsman Dec 22 '19 at 16:36
  • @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. – rici Dec 22 '19 at 16:38
  • @herdsman: `sudo apt-get install gcc-doc` if you're on Ubuntu/Debian – rici Dec 22 '19 at 16:40
  • for example it will show options from grep : `info grep --index-search=-E`, but not from gcc: `info gcc --index-search=c` (which is a little bit weird, I just copy it from here) – Herdsman Dec 22 '19 at 16:43
  • The grep info files are in a different package. I suppose you had that one installed. If `info` shows you a manpage, it means it couldn't find the relevant `info` file. On Ubuntu, at least, the GNU coreutils info files (which includes grep) are installed automatically, but the gcc info file needs to be installed manually. I find that annoying, but c'est la vie. – rici Dec 22 '19 at 16:43
  • 1
    By the way: https://askubuntu.com/questions/831/what-does-it-mean-that-a-package-is-set-to-manually-installed – rici Dec 22 '19 at 16:46
  • My wrong, now it does work, I did have installed only plain `info` package and not `gcc-doc`, But with this, Does all programs have aside man these info doc? And if so, will they be installed like `info `, just like `info gcc`? – Herdsman Dec 22 '19 at 16:47
  • 1
    @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. – rici Dec 22 '19 at 16:49